main.py 5.41 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
TRAJ=SYSTEM_NAME+'/eq_traj.trr'
GRO=SYSTEM_NAME+'/eq_final.gro'
###################################################
# {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] 
###################################################
GROUPS={'HD_GROUP':['surf',['save', ['pkl','gmx_ndx'],'time_domain_c-normal-cg']],
        'TL_GROUP':['vector'],
        'COMBINE':['tilt']
}
Stelios Karozis's avatar
Stelios Karozis committed
33 34
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
35
###################################################
Stelios Karozis's avatar
Stelios Karozis committed
36 37 38 39 40 41 42
###################################################
print(' ')
print('================')
print('Starting process')
print('================')
###################################################
###################################################
43
#Read .gro file
Stelios Karozis's avatar
Stelios Karozis committed
44
_,data_num,_,res_num,res_type,atom_type,atom_num,_ = tbf.read_gro(GRO)
Stelios Karozis's avatar
Stelios Karozis committed
45 46
print(' ')
###################################################
47 48
if os.path.isfile('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_data.pkl'):
    if LOG==1:
Stelios Karozis's avatar
Stelios Karozis committed
49
        print('WARNING: Preprocessing files exist.')
50
        print('         Erase data.pkl if the system is new.')
Stelios Karozis's avatar
Stelios Karozis committed
51
        print('--------------------------------------------')
52
    data_all=tbf.frompickle('./'+SYSTEM_NAME+'/'+SYSTEM_NAME+'_data.pkl')
Stelios Karozis's avatar
Stelios Karozis committed
53
else:
54 55 56
    #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
57
###################################################
58 59 60 61 62 63 64 65 66 67 68 69
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
70
###################################################
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        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')
86
###################################################
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        #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
108
###################################################
109 110 111 112
    else:
        for j in GROUPS[i]:
            if j=='tilt':
                tbf.SurfVector_angle(surf,vector)