Commit 377a23f2 authored by Stelios Karozis's avatar Stelios Karozis

Read gro file

parent 44162284
...@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- read all or specific part of .trr files - read all or specific part of .trr files
- calculate surface from points - calculate surface from points
- calculate angle between two vectors(3D) or lines(2D) - calculate angle between two vectors(3D) or lines(2D)
- plot points and surface
- read .gro for determine residue type and atom type
### Changed ### Changed
- None - None
......
# TooBBA # TooBBA
# Tool for Bilayer in Blocks Analysis (TooBBA) ## Tool for Bilayer in Blocks Analysis (TooBBA)
It is an tool that reads .gro files, perform a domain decomposition (user defined) and analyzes each block in terms of lipids distribution.
\ No newline at end of file It is an tool that reads .trr files, perform a domain decomposition (user defined) and analyzes each block in terms of lipids distribution.
This diff is collapsed.
import tooba_f as tbf import tooba_f as tbf
P1=(0,1,0) #P1=(0,1,0)
P2=(1,1,0) #P2=(1,1,0)
print(tbf.angle_between3D(P1,P2)) #print(tbf.angle_between3D(P1,P2))
tbf.last_fr_export(trajfile='traj.trr') #tbf.last_fr_export(trajfile='traj.trr')
print('test') tbf.read_gro_types('initial.gro')
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,12 @@ import scipy.optimize ...@@ -4,6 +4,12 @@ import scipy.optimize
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from pytrr import (
read_trr_header,
read_trr_data,
skip_trr_data,
)
def fitPlaneLTSQ(XYZ): def fitPlaneLTSQ(XYZ):
(rows, cols) = XYZ.shape (rows, cols) = XYZ.shape
G = np.ones((rows, 3)) G = np.ones((rows, 3))
...@@ -36,7 +42,7 @@ def angle_between3D(v1, v2): ...@@ -36,7 +42,7 @@ def angle_between3D(v1, v2):
else: else:
return 360 - angle return 360 - angle
def plot_surf(data, normal): def plot_surf(data, normal, c):
#Plot surface #Plot surface
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
...@@ -66,12 +72,6 @@ def plot_surf(data, normal): ...@@ -66,12 +72,6 @@ def plot_surf(data, normal):
plt.show() plt.show()
def count_frames(trajfile='traj.trr'): def count_frames(trajfile='traj.trr'):
from pytrr import (
read_trr_header,
read_trr_data,
skip_trr_data,
)
cnt_fr=0 cnt_fr=0
with open(trajfile, 'rb') as inputfile: with open(trajfile, 'rb') as inputfile:
for i in range(1000): for i in range(1000):
...@@ -84,15 +84,10 @@ def count_frames(trajfile='traj.trr'): ...@@ -84,15 +84,10 @@ def count_frames(trajfile='traj.trr'):
pass pass
return cnt_fr return cnt_fr
def last_fr_export(trajfile='traj.trr'): def fr_export(trajfile='traj.trr', num_frames=1):
from pytrr import (
read_trr_header,
read_trr_data,
skip_trr_data,
)
cnt_fr=count_frames(trajfile) cnt_fr=count_frames(trajfile)
with open(trajfile, 'rb') as inputfile: with open(trajfile, 'rb') as inputfile:
for i in range(cnt_fr-1): for i in range(cnt_fr-num_frames):
header = read_trr_header(inputfile) header = read_trr_header(inputfile)
#print('Step: {step}, time: {time}'.format(**header)) #print('Step: {step}, time: {time}'.format(**header))
skip_trr_data(inputfile, header) skip_trr_data(inputfile, header)
...@@ -103,34 +98,24 @@ def last_fr_export(trajfile='traj.trr'): ...@@ -103,34 +98,24 @@ def last_fr_export(trajfile='traj.trr'):
print(data['box']) print(data['box'])
print(data['x'][0]) print(data['x'][0])
#Random data def read_gro_types(gro):
#data = np.random.randn(100, 3)/3 cnt=0
#data[:, 2] /=10 data_num=0
with open(gro, 'r') as F:
#Find surface of points-> for lipid plane for line in F:
#c, normal = fitPlaneLTSQ(data) cnt=cnt+1
#print('Normal of surface is: ',normal) print(cnt)
if cnt>2:
#Angle between two lines-> for finding tilt res_num = line[:5]
#P1=(normal[0],normal[1], normal[2]) res_type = line[5:10]
#P2=(0,0,-0.99998042) atom_type = line[10:15]
atom_num = line[15:20]
#print('Line is: ',P2) rest_dt = line[20:]
#print('Angle between vectors is: ',angle_between3D(P1,P2)) print(res_num,res_type,atom_type,atom_num,rest_dt)
elif cnt==1:
#Fit line to points->for lipid chain system=line[:10]
#from scipy import stats elif cnt==2:
#slope, intercept, r_value, p_value, std_err = stats.linregress(data[:,0],data[:,1]) data_num=int(line[:7])
#print('y=',slope,'x+',intercept) if cnt>data_num:
#print('r_value',r_value) box_size=line[:50]
print(system,data_num,box_size)
#Angle between two lines-> for finding tilt \ No newline at end of file
#P1=(normal[0],normal[1])
#P2=(1,1)
#print('Line is: ',P2)
#print('Angle between lines is: ',angle_between2D(P1,P2))
#plot_surf(data=data, normal=normal)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment