Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
platformNames = [openmm.Platform.getPlatform(i).getName() for i in range(openmm.Platform.getNumPlatforms())]
if 'CUDA' in platformNames:
runNCMC('CUDA', relaxstepsNC, mdstep)
else:
if options.force:
runNCMC('CPU', relaxstepsNC, mdstep)
else:
print('WARNING: Could not find a valid CUDA/OpenCL platform. BLUES is not recommended on CPUs.')
print("To run on CPU: 'python blues/example.py -f'")
di_dataFN = "dihedrals%iNC_gp%i_MD1000step.txt" %(relaxstepsNC, repeat)
traj = md.load_dcd('accept.dcd', top = 'protein.pdb')
indicies = np.array([[0, 4, 6, 8]])
dihedraldata = md.compute_dihedrals(traj, indicies)
datafile = open(di_dataFN,'w')
for value in dihedraldata:
datafile.write("%s\n" % str(value)[1:-1])
datafile.close()
platformNames = [openmm.Platform.getPlatform(i).getName() for i in range(openmm.Platform.getNumPlatforms())]
if 'CUDA' in platformNames:
runNCMC('CUDA', relaxstepsNC, mdstep)
else:
if options.force:
runNCMC('CPU', relaxstepsNC, mdstep)
else:
print('WARNING: Could not find a valid CUDA/OpenCL platform. BLUES is not recommended on CPUs.')
print("To run on CPU: 'python blues/example.py -f'")
di_dataFN = "dihedrals%iNC_gp%i_MD1000step.txt" %(relaxstepsNC, repeat)
traj = md.load_dcd('accept.dcd', top = 'protein.pdb')
indicies = np.array([[0, 4, 6, 8]])
dihedraldata = md.compute_dihedrals(traj, indicies)
datafile = open(di_dataFN,'w')
for value in dihedraldata:
datafile.write("%s\n" % str(value)[1:-1])
datafile.close()
box_vectors=init_box,
velocities=init_vel)
engine.equilibrate(5)
snap = engine.current_snapshot
engine.storage.snapshots.save()
engine.initialized = True
SampleGeneratingMover.engine = engine
# this generates an order parameter (callable) object named psi (so if
# we call `psi(trajectory)` we get a list of the values of psi for each
# frame in the trajectory). This particular order parameter uses
# mdtraj's compute_dihedrals function, with the atoms in psi_atoms
psi_atoms = [6,8,14,16]
psi = CV_Function("psi", md.compute_dihedrals, trajdatafmt="mdtraj",
indices=[psi_atoms])
# same story for phi, although we won't use that
phi_atoms = [4,6,8,14]
phi = CV_Function("phi", md.compute_dihedrals, trajdatafmt="mdtraj",
indices=[phi_atoms])
# save the collectivevariables in the storage
# since they have no data cache this will only contain their name
psi.save(storage=engine.storage.collectivevariables)
phi.save(storage=engine.storage.collectivevariables)
# now we define our states and our interfaces
degrees = 180/3.14159 # psi reports in radians; I think in degrees
stateA = CVRangeVolumePeriodic(psi, -120.0/degrees, -30.0/degrees)
def getDihedral(self, positions, atomlist):
"""This function computes the dihedral angle for the given atoms at the given positions"""
top = self.structure.topology
traj = mdtraj.Trajectory(numpy.asarray(positions),top)
angle = mdtraj.compute_dihedrals(traj, atomlist)
return angle
def getDihedral(self, positions, atomlist):
"""This function computes the dihedral angle for the given atoms at the given positions"""
top = self.structure.topology
traj = mdtraj.Trajectory(np.asarray(positions),top)
angle = mdtraj.compute_dihedrals(traj, atomlist)
return angle
def load_data(self):
load_time_start = time.time()
data = []
for tfn in self.filenames:
kwargs = {} if tfn.endswith('h5') else {'top': self.top}
for t in md.iterload(tfn, chunk=self.args.split, **kwargs):
item = np.asarray(md.compute_dihedrals(t, self.indices), np.double)
data.append(item)
print('Loading data into memory + vectorization: %f s' %
(time.time() - load_time_start))
print('''Fitting with %s timeseries from %d trajectories with %d
total observations''' % (len(data), len(self.filenames),
sum(len(e) for e in data)))
return data
engine.initialized = True
SampleGeneratingMover.engine = engine
# this generates an order parameter (callable) object named psi (so if
# we call `psi(trajectory)` we get a list of the values of psi for each
# frame in the trajectory). This particular order parameter uses
# mdtraj's compute_dihedrals function, with the atoms in psi_atoms
psi_atoms = [6,8,14,16]
psi = CV_Function("psi", md.compute_dihedrals, trajdatafmt="mdtraj",
indices=[psi_atoms])
# same story for phi, although we won't use that
phi_atoms = [4,6,8,14]
phi = CV_Function("phi", md.compute_dihedrals, trajdatafmt="mdtraj",
indices=[phi_atoms])
# save the collectivevariables in the storage
# since they have no data cache this will only contain their name
psi.save(storage=engine.storage.collectivevariables)
phi.save(storage=engine.storage.collectivevariables)
# now we define our states and our interfaces
degrees = 180/3.14159 # psi reports in radians; I think in degrees
stateA = CVRangeVolumePeriodic(psi, -120.0/degrees, -30.0/degrees)
stateB = CVRangeVolumePeriodic(psi, 100/degrees, 180/degrees)
# set up minima and maxima for this transition's interface set
minima = map((1.0 / degrees).__mul__,
[-125, -135, -140, -142.5, -145.0, -147.0, 150.0])
maxima = map((1.0 / degrees).__mul__,
for index, entry in enumerate(mapped_data[0]):
frame_dict[entry].append(index)
for num in range(num_clusters):
print len(frame_dict[num])
for num in range(num_clusters):
output_name = 'tcluster_' + str(num) + '.dcd'
print 'saving ', output_name
output_traj(main_file, outname=output_name, framelist=frame_dict[num])
print mapped_data
traj = md.load(main_file)
if 1:
angle_index = np.array([[1635, 1639, 2640]]) #makes symmetric groups
angle_output = md.compute_angles(traj, angle_index)
dihedral_index = np.array([[1638, 2634, 2636, 2640]]) #separates into four groups
dihedral_output = md.compute_dihedrals(traj, dihedral_index)
frames = traj.n_frames
f, (ax1, ax2) = plt.subplots(2)
ax1.scatter(range(frames), angle_output, marker='x', s=2)
print angle_output
print dihedral_output
ax2.hist2d(angle_output[:,0], dihedral_output[:,0], bins=[40,40])
plt.show()
frames = traj.n_frames
print frames
f, (ax1, ax2) = plt.subplots(2)
ax1.scatter(range(frames), angle_output, marker='x', s=2)
ax2.hist(angle_output, bins=180)
#plt.scatter(range(frames), angle_output)