def to_mdtraj_Topology(item, atom_indices='all', check=True): if check: digest_item(item, 'file:mol2') atom_indices = digest_atom_indices(atom_indices) from mdtraj import load_mol2 from ..mdtraj_Topology import extract as extract_mdtraj_Topology tmp_item = load_mol2(item).topology tmp_item = extract_mdtraj_Topology(tmp_item) return tmp_item
def to_mdtraj_Trajectory(item, atom_indices='all', structure_indices='all', check=True): if check: digest_item(item, 'file:mol2') atom_indices = digest_atom_indices(atom_indices) structure_indices = digest_structure_indices(structure_indices) from mdtraj import load_mol2 from ..mdtraj_Trajectory import extract as extract_mdtraj_Trajectory tmp_item = load_mol2(item) tmp_item = extract_mdtraj_Trajectory(tmp_item) return tmp_item
def test_mol2_without_bonds(get_fn): trj = md.load_mol2(get_fn('li.mol2')) assert trj.topology.n_bonds == 0
def test_mol2_status_bits(get_fn): trj = md.load_mol2(get_fn('status-bits.mol2')) eq(trj.topology.n_atoms, 18) eq(trj.topology.n_bonds, 18)
def test_mol2_warnings(get_fn): trj = md.load_mol2(get_fn('lysozyme-ligand-tripos.mol2'))
def test_mol2_status_bits(): trj = md.load_mol2(get_fn('status-bits.mol2')) eq(trj.topology.n_atoms, 18) eq(trj.topology.n_bonds, 18)
def test_mol2_warnings(): trj = md.load_mol2(get_fn('lysozyme-ligand-tripos.mol2'))
def test_mol2_without_bonds(): trj = md.load_mol2(get_fn('li.mol2')) assert trj.topology.n_bonds == 0
def _create_pdb_and_topology(molecule, file_path): """Creates a uniform PDB file and `mdtraj.Topology` from an openeye molecule. Parameters ---------- molecule: openeye.oechem.OEChem The component to create the PDB and topology for. file_path: str The path pointing to where the PDB file should be created. Returns ------- mdtraj.Topology The topology of the created PDB file. """ import mdtraj from mdtraj.core import residue_names from openeye import oechem # Create a temporary mol2 file using OE, change its # residue name (sometimes OE assigns the molecule an # amino acid residue name even if that molecule is not # an amino acid, e.g. C(CO)N is not Gly), save the # altered object as a pdb. with tempfile.NamedTemporaryFile(suffix='.mol2') as mol2_file: mol2_flavor = oechem.OEOFlavor_MOL2_DEFAULT ofs = oechem.oemolostream(mol2_file.name) ofs.SetFlavor(oechem.OEFormat_MOL2, mol2_flavor) oechem.OEWriteConstMolecule(ofs, molecule) ofs.close() # Load in the OE created mol2 file. oe_mol2 = mdtraj.load_mol2(mol2_file.name) smiles = oechem.OEMolToSmiles(molecule) # Choose a random residue name. residue_map = {} for residue in oe_mol2.topology.residues: residue_map[residue.name] = None if smiles == 'O': residue_map[residue.name] = 'HOH' elif smiles == '[Cl-]': residue_map[residue.name] = 'Cl-' for atom in residue.atoms: atom.name = 'Cl-' elif smiles == '[Na+]': residue_map[residue.name] = 'Na+' for atom in residue.atoms: atom.name = 'Na+' for original_residue_name in residue_map: if residue_map[original_residue_name] is not None: continue # Make sure the residue is not already reserved, as this can occasionally # result in bonds being automatically added in the wrong places when # loading the pdb file either through mdtraj or openmm forbidden_residue_names = [ *residue_names._AMINO_ACID_CODES, *residue_names._SOLVENT_TYPES, *residue_names._WATER_RESIDUES, 'ADE', 'CYT', 'CYX', 'DAD', 'DGU', 'FOR', 'GUA', 'HID', 'HIE', 'HIH', 'HSD', 'HSH', 'HSP', 'NMA', 'THY', 'URA' ] new_residue_name = ''.join( [random.choice(string.ascii_uppercase) for _ in range(3)]) while new_residue_name in forbidden_residue_names: # Re-choose the residue name until we find a safe one. new_residue_name = ''.join( [random.choice(string.ascii_uppercase) for _ in range(3)]) residue_map[original_residue_name] = new_residue_name for residue in oe_mol2.topology.residues: residue.name = residue_map[residue.name] # Create the final pdb file. oe_mol2.save_pdb(file_path) return oe_mol2.topology
def mol2_to_pdb(mol2_filename): #convert PDB file with this name, to be used for Packmol input struct = md.load_mol2(mol2_filename) struct.save_pdb(mol2_filename[:-4] + 'pdb')
def test_load_all_mol2(mol2_file, get_fn): trj = md.load_mol2(get_fn(mol2_file))
def test_mol2_element_name(get_fn): trj = md.load_mol2(get_fn('cl.mol2')) top, bonds = trj.top.to_dataframe() assert top.iloc[0]['element'] == 'Cl'