main.py 5.76 KB
Newer Older
Stelios Karozis's avatar
Stelios Karozis committed
1
import os
Stelios Karozis's avatar
Stelios Karozis committed
2
import tooba_f as tbf
Stelios Karozis's avatar
Stelios Karozis committed
3 4 5 6 7 8
###################################################
#NOTICE:    resids of head in each subdomain may differ in tail case
#           keep all atoms of group in the first occurent subdomain
#           in case of tail is the one closest to the head, hence
#           the code is a good approximation 
###################################################
9 10 11
LOG=0
SYSTEM_NAME='test'
DISCET=[6, 6, 6]
Stelios Karozis's avatar
Stelios Karozis committed
12
NUM_FR=1
13 14
TRAJ=SYSTEM_NAME+'/eq_traj.trr'
GRO=SYSTEM_NAME+'/eq_final.gro'
15
ITP_DIC={'NS':'CER_SOVOVA.itp','FFA':'FFA_CG.itp','CHOL':'CHOL_CG.itp'}
16 17 18 19 20 21 22 23 24 25 26 27 28 29
###################################################
# {NAME:[QUEUE OF PROCESSES]}
#
#   NAME: It is user defined. A dictionary must follows with the same name.
#         The dict structure has to be: {res_type:[atom_types]}
# 
#         if NAME is COMBINATION then it needs part or all tha info from aforementioned
#         groups to execute a process. You cannot use combination as first group.
#
#   QUEUE OF PROCESSES: surf, vector, [save, [type], save_name] 
#                                           type: pkl, json, gmx_ndx (one ndx for every subdomain)
#
#                       if NAME is COMBINATION: [tilt] 
###################################################
30
GROUPS={'HD_GROUP':['surf',['save', ['pkl','gmx_ndx', 'json'],'time_domain_c-normal-cg']],
31 32 33
        'TL_GROUP':['vector'],
        'COMBINE':['tilt']
}
Stelios Karozis's avatar
Stelios Karozis committed
34 35
HD_GROUP={'NS':['C6', 'Na', 'P4', 'P3', 'C7'], 'CHOL':['ROH'], 'FFA':['AC']}
TL_GROUP={'NS':['C3', 'C4', 'C5', 'C8', 'C9', 'C10'], 'CHOL':['R1', 'R2', 'R3', 'R4', 'R5'], 'FFA':['C1', 'C2', 'C3', 'C4']}
Stelios Karozis's avatar
Stelios Karozis committed
36
###################################################
Stelios Karozis's avatar
Stelios Karozis committed
37 38 39 40 41 42 43
###################################################
print(' ')
print('================')
print('Starting process')
print('================')
###################################################
###################################################
44
#Read .gro file
Stelios Karozis's avatar
Stelios Karozis committed
45
_,data_num,_,res_num,res_type,atom_type,atom_num,_ = tbf.read_gro(GRO)
Stelios Karozis's avatar
Stelios Karozis committed
46 47
print(' ')
###################################################
48 49 50 51 52 53 54 55
#Read .itp files
#weights={}
#for MOL in ITP_DIC.keys():
#    weights_tmp = tbf.read_itp(SYSTEM_NAME+'/'+ITP_DIC[MOL])
#    weights[MOL]=weights_tmp
#    print(' ')
#print(weights)
###################################################
56 57
if os.path.isfile('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_data.pkl'):
    if LOG==1:
Stelios Karozis's avatar
Stelios Karozis committed
58
        print('WARNING: Preprocessing files exist.')
59
        print('         Erase data.pkl if the system is new.')
Stelios Karozis's avatar
Stelios Karozis committed
60
        print('--------------------------------------------')
61
    data_all=tbf.frompickle('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_data.pkl')
Stelios Karozis's avatar
Stelios Karozis committed
62
else:
63 64 65
    #Read .trr file
    data_all=tbf.fr_export(trajfile=TRAJ,num_frames=NUM_FR)
    tbf.topickle(fl=data_all, sv_name='./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_data')
Stelios Karozis's avatar
Stelios Karozis committed
66
###################################################
67 68 69 70 71 72 73 74 75 76 77 78
for i in GROUPS.keys():
    if i!='COMBINE': 
        if os.path.isfile('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_ndx.pkl'):
            if LOG==1: 
                print('WARNING: Preprocessing files exist.')
                print('         Erase ndx_HEAD.pkl if the system is new.')
                print('--------------------------------------------')
            group_ndx=tbf.frompickle('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_ndx.pkl')
        else:
            #Find atom type index in lists created above
            group_ndx=tbf.atomid_data(res_num, res_type, atom_type, atom_num, group=HD_GROUP)
            tbf.topickle(fl=group_ndx, sv_name='./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_ndx')
Stelios Karozis's avatar
Stelios Karozis committed
79
###################################################
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        if os.path.isfile('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_box.pkl'):
            if LOG==1:
                print('WARNING: Preprocessing files exist.')
                print('         Erase box.pkl if the system is new')
                print('         or new grid is applied !')
                print('--------------------------------------------')
            box_res=tbf.frompickle('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_box.pkl')
        else:
            #Create subdomains coordinates
            box_p=tbf.domain_decomposition(data=data_all,dx=DISCET[0],dy=DISCET[1],dz=DISCET[2])
            #Assign desired atoms (from above function) to subdomains
            ##result1: {step:{res:{atom_type:{atom_num:(subX,subYsubZ)}}}}
            ##result2: {step:{res:{atom_type:{(subX,subYsubZ):[atom_num]}}}}
            _,box_res=tbf.atom2grid(data_all,box_p, group_ndx)
            tbf.topickle(fl=box_res, sv_name='./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+i+'_box')
95
###################################################
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        #Creates dictionary with coordinates per subdomain for each frame
        _,coord_vector=tbf.sub_coord(box=box_res, data=data_all, res_num=res_num)
        for j in GROUPS[i]:
            if len(j) > 1:
                if j=='surf':
                    #Creates dictionary with c, normal per subdomain for each frame
                    surf=tbf.coord2norm2cg(coord_vector,img=False)
                    sv_data=surf
                if j=='vector':
                    vector=tbf.coord2vector(coord_vector)
                    sv_data=vector
            
            if len(j)==3:
                if j[0]=='save':
                    for k in j[1]:
                        if k=='pkl':
                            tbf.topickle(fl=sv_data, sv_name='./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+j[2])
                        if k=='json':    
                            tbf.tojson(fl=sv_data, sv_name='./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_'+j[2])
                        if k=='gmx_ndx':
                            tbf.togmxndx(box_res, fld='./'+SYSTEM_NAME, sv_name=SYSTEM_NAME)
Stelios Karozis's avatar
Stelios Karozis committed
117
###################################################
118 119 120
    else:
        for j in GROUPS[i]:
            if j=='tilt':
121 122
                tbf.SurfVector_angle(surf,vector)
###################################################