def test_resolve_model(self, propane_ua): constrain_mol = ConstrainedMolecule(propane_ua) constrain_mol.solve() assert constrain_mol.model_solved is True propane_solved = parmed.structure.copy(constrain_mol.structure) constrain_mol.update_xyz(propane_ua.coordinates) assert constrain_mol.model_solved is False constrain_mol.solve() assert constrain_mol.model_solved is True assert np.allclose(propane_solved.coordinates, constrain_mol.structure.coordinates)
def test_box_diethylether(self, diethylether_box): (dee_ff, box) = diethylether_box constrain_mol = ConstrainedMolecule(dee_ff) for mol in box.children: constrain_mol.update_xyz(mol.xyz * 10) # nm to angstrom constrain_mol.solve() optimized = constrain_mol.structure xyz = optimized.coordinates for bond in optimized.bonds: idx1 = bond.atom1.idx idx2 = bond.atom2.idx dist = np.sqrt(np.sum((xyz[idx2] - xyz[idx1])**2)) assert np.allclose(dist, bond.type.req)
def test_update_xyz(self, ethane_ua): constrain_mol = ConstrainedMolecule(ethane_ua) ethane_ua.coordinates[0, 0] = -1.0 ethane_ua.coordinates[0, 1] = -0.3 ethane_ua.coordinates[0, 2] = 0.2 constrain_mol.update_xyz(ethane_ua.coordinates) assert np.allclose(constrain_mol.structure.coordinates, ethane_ua.coordinates) assert np.allclose(constrain_mol.model.x_start[0].value, ethane_ua.coordinates[0, 0]) assert np.allclose(constrain_mol.model.x_start[1].value, ethane_ua.coordinates[1, 0]) assert np.allclose(constrain_mol.model.y_start[0].value, ethane_ua.coordinates[0, 1]) assert np.allclose(constrain_mol.model.y_start[1].value, ethane_ua.coordinates[1, 1]) assert np.allclose(constrain_mol.model.z_start[0].value, ethane_ua.coordinates[0, 2]) assert np.allclose(constrain_mol.model.z_start[1].value, ethane_ua.coordinates[1, 2]) assert np.allclose(constrain_mol.model.x[0].value, ethane_ua.coordinates[0, 0]) assert np.allclose(constrain_mol.model.x[1].value, ethane_ua.coordinates[1, 0]) assert np.allclose(constrain_mol.model.y[0].value, ethane_ua.coordinates[0, 1]) assert np.allclose(constrain_mol.model.y[1].value, ethane_ua.coordinates[1, 1]) assert np.allclose(constrain_mol.model.z[0].value, ethane_ua.coordinates[0, 2]) assert np.allclose(constrain_mol.model.z[1].value, ethane_ua.coordinates[1, 2])
import mbuild import foyer from constrainmol import ConstrainedMolecule ff = foyer.forcefields.load_OPLSAA() dee = mbuild.load("CCOCC", smiles=True) dee_ff = ff.apply(dee) box = mbuild.fill_box(dee, 500, density=600) box.save("unconstrained.pdb", overwrite=True) constrain_mol = ConstrainedMolecule(dee_ff) for mol in box.children: constrain_mol.update_xyz(mol.xyz * 10) # nm to angstrom constrain_mol.solve() mol.xyz = constrain_mol.xyz / 10.0 # angstrom to nm box.save("constrained.pdb", overwrite=True)
import parmed import numpy as np from constrainmol import ConstrainedMolecule # Load from gro/topology system = parmed.load_file("system.top", xyz="system.gro") system.save("unconstrained.pdb", overwrite=True) constrained_coordinates = np.zeros(system.coordinates.shape) unique_res = system.split() for (res, resids) in unique_res: constrain_mol = ConstrainedMolecule(res) for resid in resids: constrain_mol.update_xyz(system[resid, :].coordinates) constrain_mol.solve() atom_ids = [atom.idx for atom in system.residues[resid].atoms] constrained_coordinates[atom_ids] = constrain_mol.structure.coordinates system.coordinates = constrained_coordinates system.save("constrained.pdb", overwrite=True)
def test_invalid_update(self, ethane_ua): constrain_mol = ConstrainedMolecule(ethane_ua) with pytest.raises(TypeError): constrain_mol.update_xyz("string") with pytest.raises(ValueError): constrain_mol.update_xyz([[1.0, 1.0, 1.0]])