Recently I have been working on Linear combination of Distance (LCOD).
One has to extract a set of structures (may vary from 100 to 1000 to any bigger number depending on requirement, accuracy) from a very long trajectory.
If one is looking for very specific orientation, then it is necessary to go through the whole trajectory and choose the required frames and select that geometry, which is very tedious and time taking job.
But more often a random selection from the trajectory is done to take care of all the diversity in the trajectory.
In Amber, one can use ptraj to select a frame from trajectory and created its restart file to launch LCOD calculation. To launch such 100 or 1000 calculation one need to modify or create 100 or 1000 such input files to feed to ptraj with the frame number and the name of the restart file.
I am using a dictionary in python to do so.
Beginning with 2 lists:
one having frame numbers to be selected
another with name of the restart files corresponding to the different frames
I also want to give the input file a name referring to the restart file.
The initial input file know as praj.in looks like:
-----------------------
trajin md11.mdcrd 1111 1111 1
trajout md11_restart.rst restart
-----------------------
Numbers 1111 1111 are the frame numbers. So asking to select frame numbers from 1111 to 1111 i.e. only one frame.
want to create restart files by changing number 11 in second line by sequential numbers from 1 to say 100 or upto 1000.
Here is a script that first creates dictionary using 2 lists matching frame number to the number of restart file, then uses this dictionary to generate different input files which can later on launched to generate the restart files.
------------------------------
#! /usr/bin/python
# code to create dictionary and generate ptraj input files
import os
keys=[]
values=[]
inp=open("list1","r")
inp1=open("list2","r")
for line in inp.readlines():
for i in line.split():
keys.append(i)
for line1 in inp1.readlines():
for j in line1.split():
values.append(j)
print keys
print values
dictionary=dict(zip(keys,values))
print dictionary
print keys
print values
for keys, values in dictionary.items():
print keys
print values
fin = open("praj.in","r")
fout = open("praj_"+str(values)+".in", "w")
for line in fin:
source="1111 1111"
final= keys+" "+keys
source1="md11_"
final1= "md"+str(values)+"_"
line=line.replace(source, final)
print line
line=line.replace(source1, final1)
print line
fout.write(line)
fin.close()
fout.close()
print "\nfiles praj_values.in are created\n"
--------------------------------
So the initial praj.in file was modified and saved by different names as praj_1.in, praj_2.in etc.
One of the modified file "praj_2.in" looks like:
-----------------------------
trajin md11.mdcrd 985 985 1
trajout md2_restart.rst restart
-------------------
Frame no. 985 will be selected as a restart point for the 2nd run out of 100 or 1000's of similar run
One has to extract a set of structures (may vary from 100 to 1000 to any bigger number depending on requirement, accuracy) from a very long trajectory.
If one is looking for very specific orientation, then it is necessary to go through the whole trajectory and choose the required frames and select that geometry, which is very tedious and time taking job.
But more often a random selection from the trajectory is done to take care of all the diversity in the trajectory.
In Amber, one can use ptraj to select a frame from trajectory and created its restart file to launch LCOD calculation. To launch such 100 or 1000 calculation one need to modify or create 100 or 1000 such input files to feed to ptraj with the frame number and the name of the restart file.
I am using a dictionary in python to do so.
Beginning with 2 lists:
one having frame numbers to be selected
another with name of the restart files corresponding to the different frames
I also want to give the input file a name referring to the restart file.
The initial input file know as praj.in looks like:
-----------------------
trajin md11.mdcrd 1111 1111 1
trajout md11_restart.rst restart
-----------------------
Numbers 1111 1111 are the frame numbers. So asking to select frame numbers from 1111 to 1111 i.e. only one frame.
want to create restart files by changing number 11 in second line by sequential numbers from 1 to say 100 or upto 1000.
Here is a script that first creates dictionary using 2 lists matching frame number to the number of restart file, then uses this dictionary to generate different input files which can later on launched to generate the restart files.
------------------------------
#! /usr/bin/python
# code to create dictionary and generate ptraj input files
import os
keys=[]
values=[]
inp=open("list1","r")
inp1=open("list2","r")
for line in inp.readlines():
for i in line.split():
keys.append(i)
for line1 in inp1.readlines():
for j in line1.split():
values.append(j)
print keys
print values
dictionary=dict(zip(keys,values))
print dictionary
print keys
print values
for keys, values in dictionary.items():
print keys
print values
fin = open("praj.in","r")
fout = open("praj_"+str(values)+".in", "w")
for line in fin:
source="1111 1111"
final= keys+" "+keys
source1="md11_"
final1= "md"+str(values)+"_"
line=line.replace(source, final)
print line
line=line.replace(source1, final1)
print line
fout.write(line)
fin.close()
fout.close()
print "\nfiles praj_values.in are created\n"
--------------------------------
So the initial praj.in file was modified and saved by different names as praj_1.in, praj_2.in etc.
One of the modified file "praj_2.in" looks like:
-----------------------------
trajin md11.mdcrd 985 985 1
trajout md2_restart.rst restart
-------------------
Frame no. 985 will be selected as a restart point for the 2nd run out of 100 or 1000's of similar run
Comments
Post a Comment