Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Now let's make make the output assignments start with zero at the first position.
i0 = trimmed_assignments[0][0]
if i0 == 1:
for m in trimmed_assignments:
m *= -1
m += 1
pairs = msm.draw_samples(trimmed_assignments, 2000)
samples = map_drawn_samples(pairs, data)
mu = np.mean(samples, axis=1)
eq(mu, np.array([[0., 0., 0.0], [25., 25., 25.]]), decimal=1)
# We should make sure we can sample from Trajectory objects too...
# Create a fake topology with 1 atom to match our input dataset
top = md.Topology.from_dataframe(pd.DataFrame({"serial":[0], "name":["HN"], "element":["H"], "resSeq":[1], "resName":"RES", "chainID":[0]}), bonds=np.zeros(shape=(0, 2), dtype='int'))
trajectories = [md.Trajectory(x[:, np.newaxis], top) for x in data] # np.newaxis reshapes the data to have a 40000 frames, 1 atom, 3 xyz
trj_samples = map_drawn_samples(pairs, trajectories)
mu = np.array([t.xyz.mean(0)[0] for t in trj_samples])
eq(mu, np.array([[0., 0., 0.0], [25., 25., 25.]]), decimal=1)
for key, el in elements.iteritems():
try:
md.element.Element(
number=int(el[0]), name=el[1], symbol=el[2], mass=float(el[3])
)
simtk.openmm.app.Element(
number=int(el[0]), name=el[1], symbol=el[2], mass=float(el[3])*units.amu
)
except(AssertionError):
pass
atoms = pd.DataFrame(top_dict['atoms'], columns=top_dict['atom_columns'])
bonds = np.array(top_dict['bonds'])
return md.Topology.from_dataframe(atoms, bonds)
JSON string representing the topology of system being simulated.
"""
n_atoms = 1
data = []
for i in range(n_atoms):
data.append(dict(serial=i, name="H", element="H",
resSeq=i + 1, resName="UNK", chainID=0))
data = pd.DataFrame(data)
xyz = np.zeros((1, 1, 3))
unitcell_lengths = 0.943 * np.ones((1, 3))
unitcell_angles = 90 * np.ones((1, 3))
top = mdj.Topology.from_dataframe(data, bonds=np.zeros((0, 2), dtype='int'))
json_top_str = mdtraj_to_json_topology(top)
return json_top_str
def to_mdtraj(self):
atoms, bonds = self.atoms, self.bonds
atoms_mdtraj = atoms[["name", "resName"]]
atoms_mdtraj["serial"] = atoms.index
atoms_mdtraj["element"] = atoms.atype.map(gaff_elements)
atoms_mdtraj["resSeq"] = np.ones(len(atoms))
atoms_mdtraj["chainID"] = np.ones(len(atoms))
bonds_mdtraj = bonds[["id0", "id1"]].values
offset = bonds_mdtraj.min()
bonds_mdtraj -= offset
top = mdtraj.Topology.from_dataframe(atoms_mdtraj, bonds_mdtraj)
xyzlist = np.array([atoms[["x","y","z"]].values])
xyzlist /= 10.0 # Convert from angstrom to nanometer
traj = mdtraj.Trajectory(xyzlist, top)
return traj
data = []
for i in range(n_atoms):
data.append(dict(serial=i, name="H", element="H", resSeq=i + 1, resName="UNK", chainID=0))
# convert to pandas data frame format
data = pd.DataFrame(data)
# creates the array of position for the system
xyz = np.zeros((1, 1, 3))
# defines box vector lengths
unitcell_lengths = 0.943 * np.ones((1, 3))
unitcell_angles = 90 * np.ones((1, 3))
# create the topology and the trajectory of teh randomwalk systes
top = mdj.Topology.from_dataframe(data, bonds=np.zeros((0, 2), dtype='int'))
traj = mdj.Trajectory(xyz, top, unitcell_lengths=unitcell_lengths, unitcell_angles=unitcell_angles)
#save the trajectory in h5 and pdb format
traj.save_hdf5("tmp_mdtraj_system.h5")
# we need a JSON string for now in the topology section of the
# HDF5 so we just load the topology from the hdf5 file
top_h5 = h5py.File("tmp_mdtraj_system.h5")
# it is in bytes so we need to decode to a string, which is in JSON format
json_top_str = top_h5['topology'][0].decode()
top_h5.close()
# write the JSON topology out
with open("randomwalk_system.top.json", mode='w') as json_wf:
json_wf.write(json_top_str)
def __setstate__(self, serialization):
topology_dict = serialization['topology']
atoms = pandas.read_json(topology_dict['atoms'], orient='records')
bonds = np.array(topology_dict['bonds'])
self._topology = mdtraj.Topology.from_dataframe(atoms, bonds)
self._ligand_atoms = serialization['ligand_atoms']
self._solvent_atoms = serialization['solvent_atoms']
self._regions = serialization['regions']
# for key, el in elements.iteritems():
# try:
# md.element.Element(
# number=int(el[0]), name=el[1], symbol=el[2], mass=float(el[3])
# )
# simtk.openmm.app.Element(
# number=int(el[0]), name=el[1], symbol=el[2], mass=float(el[3])*units.amu
# )
# except(AssertionError):
# pass
atoms = pd.DataFrame(top_dict['atoms'], columns=top_dict['atom_columns'])
bonds = np.array(top_dict['bonds'])
md_topology = md.Topology.from_dataframe(atoms, bonds)
return cls(md_topology, dct['subsets'])
def _deserialize_topology(topology_json):
"""Create MDTraj topology from JSON-serialized version"""
table, bonds = json.loads(topology_json)
topology_df = pd.read_json(table)
topology = md.Topology.from_dataframe(topology_df,
np.array(bonds))
return topology