Skip to content

Instantly share code, notes, and snippets.

@yukimya
Last active August 29, 2015 14:01
Show Gist options
  • Save yukimya/05ff40ca78d092e75414 to your computer and use it in GitHub Desktop.
Save yukimya/05ff40ca78d092e75414 to your computer and use it in GitHub Desktop.
# GPL v 3.0
# script name: calcDistanceDCD.py
# written by Naoyuki Miyashita on 12/18/2013
# Naoyuki Miyashita (c) 2013
#
#-----------------------------------
# Use lProam, pylab, numpy
#-----------------------------------
# ussage:
#
# file="new.pdb"
# dcd="test.dcd"
# python calc DistanceDCD.py $file $dcd \
# "resnum 1to2 and name CA" \
# "resnum 4to5 and name CA"
#-----------------------------------
# Please use prody selection rules in the atom selections.
#
from prody import *
from pylab import *
import numpy as np
import lProam
#
def argv_read():
filename = sys.argv[1] # input.pdb
dcdfile = sys.argv[2] # input.dcd
selec1 = sys.argv[3] # "segment A"
selec2 = sys.argv[4] # "segment B"
argv_array=(filename,dcdfile,selec1,selec2)
return(argv_array)
def get_pdb_center(filename,center_selec):
#read pdb
center = np.array([])
pdb1 = lProam.file_read(filename)
key_pdb = pdb1.select(center_selec)
#setup pdb
cent = center_selec + " and name CA"
center = lProam.get_center(key_pdb,center_selec)
# copy pdb
return(center)
def main_calc():
#input
argv_array=argv_read()
(filename,dcdfile,select1,select2)=argv_array
#
# read and setup pdb
pdb = lProam.file_read(filename)
#print pdb
dcd = lProam.dcd_trj(dcdfile)
#print dcd
dcd.link(pdb)
dcd.setCoords(pdb)
#(pdb,dcd)=lProam.readFrame(filename,dcdfile)
#print dcd
a1 = pdb.select(select1)
a2 = pdb.select(select2)
#print a1, a2
dist = zeros(dcd.numFrames())
#dist = zeros(arange(dcd))
for i, frame in enumerate(dcd):
c1 = calcCenter(a1)
c2 = calcCenter(a2)
#dist[i] = calcDistance(a1, a2)
dist[i] = calcDistance(c1, c2)
#print "DISTANCE=",dist[i]
print i," ", dist[i]
return()
if __name__ == '__main__':
main_calc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment