Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_4():
# using a really big box, we should get the same results with and without
# pbcs
box = np.array([[100, 0, 0], [0, 200, 0], [0, 0, 300]])
box = np.zeros((N_FRAMES, 3, 3)) + box # broadcast it out
a = _displacement_mic(xyz, pairs, box, False)
b = _displacement(xyz, pairs)
eq(a, b, decimal=3)
def test_multiread(get_fn):
reference = md.load(get_fn('frame0.mdcrd'), top=get_fn('native.pdb'))
with MDCRDTrajectoryFile(get_fn('frame0.mdcrd'), n_atoms=22) as f:
xyz0, box0 = f.read(n_frames=1)
xyz1, box1 = f.read(n_frames=1)
eq(reference.xyz[0], xyz0[0] / 10)
eq(reference.xyz[1], xyz1[0] / 10)
def test_read_0(get_fn):
with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
xyz = f.read()
with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
xyz3 = f.read(stride=3)
eq(xyz[::3], xyz3)
def test_box(get_fn):
t = md.load(get_fn('native.pdb'))
assert eq(t.unitcell_vectors, None)
assert eq(t.unitcell_lengths, None)
assert eq(t.unitcell_angles, None)
assert eq(t.unitcell_volumes, None)
t.unitcell_vectors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]).reshape(1, 3, 3)
assert eq(np.array([1.0, 1.0, 1.0]), t.unitcell_lengths[0])
assert eq(np.array([90.0, 90.0, 90.0]), t.unitcell_angles[0])
assert eq(np.array([1.0]), t.unitcell_volumes)
def test_seek(get_fn):
reference = md.load(get_fn('frame0.xyz'), top=get_fn('native.pdb'))
with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
f.seek(1)
eq(1, f.tell())
xyz1 = f.read(n_frames=1)
eq(reference.xyz[1], xyz1[0] / 10)
f.seek(10)
eq(10, f.tell())
xyz10 = f.read(n_frames=1)
eq(reference.xyz[10], xyz10[0] / 10)
eq(11, f.tell())
f.seek(-8, 1)
xyz3 = f.read(n_frames=1)
eq(reference.xyz[3], xyz3[0] / 10)
f.seek(4, 1)
xyz8 = f.read(n_frames=1)
eq(reference.xyz[8], xyz8[0] / 10)
def test_read_chunk1(get_fn, fn_xtc):
with XTCTrajectoryFile(fn_xtc, 'r', chunk_size_multiplier=0.5) as f:
xyz, time, step, box = f.read()
iofile = io.loadh(get_fn('frame0.xtc.h5'), deferred=False)
assert eq(xyz, iofile['xyz'])
assert eq(step, iofile['step'])
assert eq(box, iofile['box'])
assert eq(time, iofile['time'])
def test_restrict_atoms(get_fn):
traj = md.load(get_fn('traj.h5'))
time_address = traj.time.ctypes.data
desired_atom_indices = [0, 1, 2, 5]
traj.restrict_atoms(desired_atom_indices)
atom_indices = [a.index for a in traj.top.atoms]
eq([0, 1, 2, 3], atom_indices)
eq(traj.xyz.shape[1], 4)
eq(traj.n_atoms, 4)
eq(traj.n_residues, 1)
eq(len(traj.top._bonds), 2)
eq(traj.n_residues, traj.topology._numResidues)
eq(traj.n_atoms, traj.topology._numAtoms)
eq(np.array([a.index for a in traj.topology.atoms]), np.arange(traj.n_atoms))
# assert that the time field was not copied
assert traj.time.ctypes.data == time_address
def test_read_write_4(get_fn):
traj = md.load(get_fn('frame0.nc'), top=get_fn('native.pdb'))
traj[0].save(temp2)
assert os.path.exists(temp2)
rsttraj = md.load(temp2, top=get_fn('native.pdb'))
eq(rsttraj.xyz, traj[0].xyz)
os.unlink(temp2)
traj.save(temp2)
for i in range(traj.n_frames):
assert os.path.exists('%s.%03d' % (temp2, i + 1))
os.unlink('%s.%03d' % (temp2, i + 1))
# HETATM19787 S SO4 D 804 -4.788 -9.395 22.515 1.00121.87 S
# HETATM19788 O1 SO4 D 804 -3.815 -9.511 21.425 1.00105.97 O
# HETATM19789 O2 SO4 D 804 -5.989 -8.733 21.999 1.00116.13 O
# HETATM19790 O3 SO4 D 804 -5.130 -10.726 23.043 1.00108.74 O
# HETATM19791 O4 SO4 D 804 -4.210 -8.560 23.575 1.00112.54 O
t1 = load_pdb(get_fn('3nch.pdb.gz'))
top, bonds = t1.top.to_dataframe()
top2 = Topology.from_dataframe(top, bonds)
eq(t1.top, top2)
top = top.set_index('serial') # Index by the actual data in the PDB
eq(str(top.ix[19791]["name"]), "O4")
eq(str(top.ix[19787]["name"]), "S")
eq(str(top.ix[19787]["resName"]), "SO4")
eq(int(top.ix[19787]["resSeq"]), 804)
integrator = LangevinIntegrator(300 * kelvin, 1.0 / picoseconds, 2.0 * femtoseconds)
integrator.setConstraintTolerance(0.00001)
platform = Platform.getPlatformByName('Reference')
simulation = Simulation(pdb.topology, system, integrator, platform)
simulation.loadCheckpoint(checkpoint)
reporter = XTCReporter(xtcfile, 2, append=True)
simulation.reporters.append(reporter)
simulation.step(10)
reporter.close()
xtc_traj = md.load(xtcfile, top=get_fn('native.pdb'))
xtc_traj_cp = md.load(xtcfile_cp, top=get_fn('native.pdb'))
eq(xtc_traj.xyz[:5], xtc_traj_cp.xyz)
eq(xtc_traj.n_frames, 10)
eq(xtc_traj_cp.n_frames, 5)
eq(xtc_traj.time[:5], xtc_traj_cp.time)