Created
February 8, 2016 17:05
-
-
Save mgoldey/15d86dcf1cf33204f561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ase | |
from ase import io | |
import os,time | |
import numpy as np | |
import itertools | |
import matplotlib.pyplot as plt | |
import matplotlib | |
fl=os.popen("ls *.pdb").read().split()[0] | |
mol=io.read(fl) | |
mol.set_pbc(True) | |
nat=len(mol.numbers) | |
radii=covalent_radii[mol.numbers] | |
dm=[[7, 8, 96, 95], [7, 6, 9, 13], [19, 20, 84, 83], [83, 82, 85, 89], [159, 160, 248, 247], [159, 158, 161, 165], [171, 172, 236, 235], [235, 234, 237, 241]] | |
Ds=[] | |
for ifl,fl in enumerate(os.popen("ls *.pdb").read().split()): | |
mol=io.read(fl) | |
mol.set_pbc(True) | |
d2s=[] | |
for i in dm: | |
imol=mol[i] | |
if (imol.get_all_distances()==imol.get_all_distances(mic=True)).all(): | |
d2s.append(mol.get_dihedral(i)) | |
else: | |
for iat in range(3): | |
for idir in range(3): | |
d=imol.positions[iat+1]-imol.positions[0] | |
if (d[idir]>imol.cell[idir,idir]/2.): | |
imol.positions[iat+1]-=imol.cell[idir] | |
if (d[idir]<-imol.cell[idir,idir]/2.): | |
imol.positions[iat+1]+=imol.cell[idir] | |
d2s.append(imol.get_dihedral([0,1,2,3])) | |
Ds.append(d2s) | |
Ds=np.array(Ds)*180./np.pi | |
from copy import deepcopy | |
thresh=250. | |
D2=deepcopy(Ds) | |
for i in range(len(Ds[0])): | |
iwrap=0 | |
for j in range(len(Ds)-1): | |
if ((Ds[j+1,i]+iwrap*360-D2[j,i])>thresh): | |
iwrap-=1 | |
elif ((Ds[j+1,i]+iwrap*360-D2[j,i])<-thresh): | |
iwrap+=1 | |
D2[j+1,i]+=iwrap*360.0 | |
fig,ax1=plt.subplots(1,1,sharex=True,figsize=(18,10)) | |
ld=float(len(Ds[0])) | |
for i in range(int(ld)): | |
plt.plot(np.arange(200),D2[:,i],label="Dihedral_"+str(i),color=matplotlib.cm.hsv(float(i)/ld)) | |
plt.legend() | |
plt.xlabel("Timestep") | |
plt.ylabel("Dihedral angle") | |
plt.xkcd() | |
plt.savefig("dih_vs_time.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment