From cec97309403b4f2f3fa3012bd0486ba6e407d3f7 Mon Sep 17 00:00:00 2001 From: skarozis Date: Thu, 14 May 2020 16:35:19 +0300 Subject: [PATCH] Corrections --- CHANGELOG | 2 ++ main.py | 34 +++++++++++++++++++++------------- tooba_f.py | 31 ++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1ce064b..7614f20 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - code for assign coordinates to subdomain - code for creating vectors for each tail of lipid in subdomain - code for creating surface for heads of lipids in subdomain +- code for calculating the angle between surface and vectors for every step, sudomain and resid +- clean main.py ### Changed - change output in def atomid_data() to include resid diff --git a/main.py b/main.py index 1eea020..3f0f399 100644 --- a/main.py +++ b/main.py @@ -1,21 +1,29 @@ import tooba_f as tbf - -#P1=(0,1,0) -#P2=(1,1,0) -#print(tbf.angle_between3D(P1,P2)) - +################################################### +#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 +################################################### +TRAJ='traj.trr' +NUM_FR=1 +GRO='initial.gro' +HEAD=True +HD_GROUP={'MMA':['C1', 'C2']} +TAIL=True +TL_GROUP={'MMA':['C3', 'C4', 'C5']} +################################################### #Read .trr file -data_all=tbf.fr_export(trajfile='traj.trr',num_frames=1) +data_all=tbf.fr_export(trajfile=TRAJ,num_frames=NUM_FR) #Read .gro file -_,data_num,_,res_num,res_type,atom_type,atom_num,_ = tbf.read_gro('initial.gro') +_,data_num,_,res_num,res_type,atom_type,atom_num,_ = tbf.read_gro(GRO) #Create subdomains coordinates box_p=tbf.domain_decomposition(data=data_all,dx=2,dy=2,dz=2) ################################################### -HEAD=False if HEAD==True: #Find atom type index in lists created above - group_ndx=tbf.atomid_data(res_num, atom_type, atom_num, group={'MMA':['C1', 'C2']}) + group_ndx=tbf.atomid_data(res_num, atom_type, atom_num, group=HD_GROUP) #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]}}}} @@ -24,16 +32,16 @@ if HEAD==True: coord_norm,_=tbf.sub_coord(box=box_res, data=data_all, res_num=res_num) #Creates dictionary with c, normal per subdomain for each frame surf=tbf.coord2norm(coord_norm,img=True) - ################################################### -TAIL=True if TAIL==True: #Find atom type index in lists created above - group_ndx=tbf.atomid_data(res_num, atom_type, atom_num, group={'MMA':['C3', 'C4', 'C5']}) + group_ndx=tbf.atomid_data(res_num, atom_type, atom_num, group=TL_GROUP) #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) #Creates dictionary with coordinates per subdomain for each frame _,coord_vector=tbf.sub_coord(box=box_res, data=data_all, res_num=res_num) - vector=tbf.coord2vector(coord_vector) \ No newline at end of file + vector=tbf.coord2vector(coord_vector) +################################################### +tbf.SurfVector_angle(surf,vector) \ No newline at end of file diff --git a/tooba_f.py b/tooba_f.py index 053c650..3497f3f 100644 --- a/tooba_f.py +++ b/tooba_f.py @@ -404,10 +404,9 @@ def coord2vector(coord_vector): Use the coord_vector from 'def sub_coord' and replaces XYZ coordinates with vector of best fit line - parameters: coord = {step:{subdomain:array[[X1,Y1,Z1] ... [Xn,Yn,Zn]]}} - img = True or False - - output: dictionary = {step:{subdomain:[x, y, z]} + parameters: coord = {step:{subdomain:{resid:[[X1,Y1,Z1] ... [Xn,Yn,Zn]]}} + + output: dictionary = {step:{subdomain:{resid:[x, y, z]}} """ vector={} for step in coord_vector.keys(): @@ -417,4 +416,26 @@ def coord2vector(coord_vector): for resid in coord_vector[step][subdomain].keys(): vv = points2vector(np.array(coord_vector[step][subdomain][resid])) vector[step][subdomain][resid]=vv - return vector \ No newline at end of file + return vector + +def SurfVector_angle(surf,vector): + """ + Use the surf and vector from 'def coord2norm' and 'def coord2vector' + and calculate the angle between them for every step, sudomain and resid + + parameters: surf = {step:{subdomain:{c:int, normal:array[]}}} + vector = {step:{subdomain:{resid:[x, y, z]}} + + output: angle = {step:{subdomain:{resid:angle}} + """ + angle={} + for step in surf.keys(): + angle[step]={} + for sudomain in surf[step].keys(): + angle[step][sudomain]={} + for resid in vector[step][sudomain].keys(): + P1=tuple(surf[step][sudomain]['normal']) + P2=tuple(vector[step][sudomain][resid]) + #print(tbf.angle_between3D(P1,P2)) + angle[step][sudomain][resid]=angle_between3D(P1,P2) + return angle \ No newline at end of file -- 2.24.1