Tspostat in python. Flexible and incremental
Samo Penic
2019-02-26 3736abcc64f8b9c80f462c68722256db3b29c5c3
Added removal of already poststated files
1 files modified
1 files added
42 ■■■■■ changed files
devel.py 5 ●●●●● patch | view | raw | blame | history
poststat.py 37 ●●●●● patch | view | raw | blame | history
devel.py
New file
@@ -0,0 +1,5 @@
import poststat
poststat.clean_poststat_directory(".")
j=poststat.poststat_directory(".")
poststat.py
@@ -6,6 +6,7 @@
import multiprocessing
import django
from time import sleep
import math
def count_bonds_with_energy(blist):
    cnt=0
@@ -14,7 +15,25 @@
            cnt+=1
    return cnt
def average_normal_force_in_vtu(vesicle):
    F=[0,0,0]
    for i in range(0,vesicle.contents.vlist.contents.n):
        cvtx=vesicle.contents.vlist.contents.vtx[i]
        if(abs(cvtx.contents.c)>1e-15):
            normal=[0,0,0]
            for k in range(0,cvtx.contents.tristar_no):
                normal[0]=normal[0]+cvtx.contents.tristar[k].contents.xnorm
                normal[1]=normal[1]+cvtx.contents.tristar[k].contents.ynorm
                normal[2]=normal[2]+cvtx.contents.tristar[k].contents.znorm
            F[0]=F[0]+normal[0]/math.sqrt(pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2))
            F[1]=F[1]+normal[1]/math.sqrt(pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2))
            F[2]=F[2]+normal[2]/math.sqrt(pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2))
    #F=[f*vesicle.contents.tape.contents.F for f in F]
    return F
def sum_stretching_energy(vesicle, only_c0_c0=False):
    return 0.0
    energy=0.0
    for i in range(0,vesicle.contents.tlist.contents.n):
#        if (only_c0_c0 is True 
@@ -47,6 +66,7 @@
    l1,l2,l3=ts.gyration_eigen(vesicle)
    hbar=ts.vesicle_meancurvature(vesicle)/vesicle.contents.area
    count_bonds=count_bonds_with_energy(vesicle.contents.blist)
    avg_normal_force=average_normal_force_in_vtu(vesicle)
    retval={'volume':vesicle.contents.volume,
        'area': vesicle.contents.area,
        'hbar':hbar,
@@ -55,6 +75,9 @@
        'l3':l3,
        'Nbw/Nb':count_bonds/vesicle.contents.blist.contents.n,
        'StretchingE': sum_stretching_energy(vesicle),
        'avgFx': avg_normal_force[0],
        'avgFy': avg_normal_force[1],
        'avgFz': avg_normal_force[2]
        }
    return retval
@@ -92,7 +115,7 @@
        csvdict=read_csv(os.path.join(directory,'data_tspoststat.csv'))
    except FileNotFoundError:
        #print("no file")
        csvdict={'OuterLoop':['OuterLoop', 'Volume', 'Area', 'lamdba1', 'lambda2', 'lambda3', 'Nbw/Nb', 'hbar', 'StretchingE']}
        csvdict={'OuterLoop':['OuterLoop', 'Volume', 'Area', 'lamdba1', 'lambda2', 'lambda3', 'Nbw/Nb', 'hbar', 'StretchingE', 'avgFx', 'avgFy', 'avgFz']}
    filedict=get_vtu_dict(directory)
    modified=False
    for f in filedict:
@@ -114,11 +137,20 @@
                '{:.17e}'.format(p['l3']),
                '{:.17e}'.format(p['Nbw/Nb']),
                '{:.17e}'.format(p['hbar']),
                '{:.17e}'.format(p['StretchingE'])]
                '{:.17e}'.format(p['StretchingE']),
                '{:.17e}'.format(p['avgFx']),
                '{:.17e}'.format(p['avgFy']),
                '{:.17e}'.format(p['avgFz'])]
            modified=True
    if modified:
        write_csv(os.path.join(directory,'data_tspoststat.csv'), csvdict)
        
def clean_poststat_directory(directory):
    """Function deletes data_tspoststat.csv created by tspoststat in given directory, enabling forcing of re-tspostating it"""
    try:
        os.remove(os.path.join(directory, 'data_tspoststat.csv'))
    except FileNotFoundError:
        pass
class PostProcess(multiprocessing.Process):
@@ -127,6 +159,7 @@
        self.dirlist=dirlist
    def run(self):
        for d in self.dirlist:
            clean_poststat_directory(d)
            poststat_directory(d)
            print("Directory {} done".format(d))
        print("All done for this process")