def test_topology_virtualsites_atom_indexing(self): """ Add multiple instances of the same molecule, but in a different order, and ensure that virtualsite atoms are indexed correctly """ topology = Topology() topology.add_molecule(create_ethanol()) topology.add_molecule(create_ethanol()) topology.add_molecule(create_reversed_ethanol()) # Add a virtualsite to the reference ethanol for ref_mol in topology.reference_molecules: ref_mol._add_bond_charge_virtual_site( [0, 1], 0.5 * unit.angstrom, ) virtual_site_topology_atom_indices = [(0, 1), (9, 10), (26, 25)] for top_vs, expected_indices in zip( topology.topology_virtual_sites, virtual_site_topology_atom_indices): assert (tuple([at.topology_particle_index for at in top_vs.atoms]) == expected_indices) assert top_vs.atom( 0).topology_particle_index == expected_indices[0] assert top_vs.atom( 1).topology_particle_index == expected_indices[1]
def test_from_openmm_missing_reference(self): """Test creation of an openforcefield Topology object from an OpenMM Topology when missing a unique molecule""" from simtk.openmm import app pdbfile = app.PDBFile( get_data_file_path( 'systems/packmol_boxes/cyclohexane_ethanol_0.4_0.6.pdb')) molecules = [create_ethanol()] with pytest.raises( ValueError, match='No match found for molecule C6H12') as excinfo: topology = Topology.from_openmm(pdbfile.topology, unique_molecules=molecules)
def test_from_openmm(self): """Test creation of an openforcefield Topology object from an OpenMM Topology and component molecules""" from simtk.openmm import app pdbfile = app.PDBFile( get_data_file_path( 'systems/packmol_boxes/cyclohexane_ethanol_0.4_0.6.pdb')) molecules = [create_ethanol(), create_cyclohexane()] topology = Topology.from_openmm(pdbfile.topology, unique_molecules=molecules) assert topology.n_reference_molecules == 2 assert topology.n_topology_molecules == 239
def test_to_file_multi_molecule_different_order(self): """ Checks for the following if Topology.to_write maintains the order of atoms for the same molecule with different indexing """ from tempfile import NamedTemporaryFile from openforcefield.tests.test_forcefield import ( create_ethanol, create_reversed_ethanol, ) from openforcefield.topology import Molecule, Topology topology = Topology() topology.add_molecule(create_ethanol()) topology.add_molecule(create_reversed_ethanol()) mol = Molecule.from_pdb_and_smiles( get_data_file_path("systems/test_systems/1_ethanol.pdb"), "CCO") positions = mol.conformers[0] # Make up coordinates for the second ethanol by translating the first by 10 angstroms # (note that this will still be a gibberish conformation, since the atom order in the second molecule is different) positions = np.concatenate( [positions, positions + 10.0 * unit.angstrom]) element_order = [] with NamedTemporaryFile(suffix=".pdb") as iofile: topology.to_file(iofile.name, positions) data = open(iofile.name).readlines() for line in data: if line.startswith("HETATM"): element_order.append(line.strip()[-1]) assert element_order == [ "C", "C", "O", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "O", "C", "C", ]
from openforcefield.tests.test_forcefield import create_ethanol mol = create_ethanol() from openforcefield.utils.toolkits import * AmberToolsToolkitWrapper().assign_fractional_bond_orders(mol) print(mol.get_bond_between(1, 2).fractional_bond_order)