Пример #1
0
 def test_get_mol2_gaff_atom_types(self):
     """Test that a warning is raised OpenEyeToolkitWrapper when it detects GAFF atom types in a mol2 file."""
     toolkit_wrapper = OpenEyeToolkitWrapper()
     mol2_file_path = get_data_file_path(
         'molecules/AlkEthOH_test_filt1_ff.mol2')
     with pytest.warns(GAFFAtomTypeWarning, match='SYBYL'):
         Molecule.from_file(mol2_file_path,
                            toolkit_registry=toolkit_wrapper)
def qcmiles(jsmol, toolkit='rdkit'):

    import cmiles
    from openbabel import openbabel
    from openforcefield.topology.molecule import Molecule

    obConversion = openbabel.OBConversion()
    obConversion.SetInAndOutFormats("xyz", "sdf")
    obmol = openbabel.OBMol()

    xyz_str = dict_to_xyz_string(jsmol)

    obConversion.ReadString(obmol, xyz_str)
    sdf = obConversion.WriteString(obmol)

    with io.StringIO(sdf) as sdf_stream:
        qcmol = Molecule.from_file(sdf_stream,
                                   file_format='SDF').to_qcschema().dict()

    # would be nice if oFF could handle data as strings to avoid IO
    #with open('mol.sdf','w') as f:
    #    f.write(sdf)

    #qcmol = Molecule.from_file('mol.sdf').to_qcschema().dict()
    #os.remove("mol.sdf")

    # cmiles wants the schema with a flat xyz
    if len(qcmol['geometry'].shape) > 1:
        qcmol['geometry'] = np.reshape(qcmol['geometry'], (-1, ))

    attribs = cmiles.generator.get_molecule_ids(qcmol, toolkit=toolkit)
    return attribs
Пример #3
0
 def test_load_aromatic_pdb(self):
     """Test OpenEyeToolkitWrapper for importing molecule conformers"""
     toolkit_wrapper = RDKitToolkitWrapper()
     filename = get_data_file_path('molecules/toluene.pdb')
     molecule = Molecule.from_file(filename,
                                   toolkit_registry=toolkit_wrapper)
     assert len(molecule._conformers) == 1
     assert molecule._conformers[0].shape == (15, 3)
Пример #4
0
 def test_get_pdb_coordinates(self):
     """Test RDKitToolkitWrapper for importing a single set of coordinates from a pdb file"""
     toolkit_wrapper = RDKitToolkitWrapper()
     filename = get_data_file_path('molecules/toluene.pdb')
     molecule = Molecule.from_file(filename,
                                   toolkit_registry=toolkit_wrapper)
     assert len(molecule._conformers) == 1
     assert molecule._conformers[0].shape == (15, 3)
Пример #5
0
 def test_get_multiconformer_sdf_coordinates(self):
     """Test RDKitToolkitWrapper for importing a single set of coordinates from a sdf file"""
     raise NotImplementedError
     toolkit_wrapper = RDKitToolkitWrapper()
     filename = get_data_file_path('molecules/toluene.sdf')
     molecule = Molecule.from_file(filename,
                                   toolkit_registry=toolkit_wrapper)
     assert len(molecule._conformers) == 1
     assert molecule._conformers[0].shape == (15, 3)
Пример #6
0
 def test_get_sdf_coordinates(self):
     """Test RDKitToolkitWrapper for importing a single set of coordinates from a sdf file"""
     toolkit_wrapper = RDKitToolkitWrapper()
     filename = get_data_file_path('molecules/toluene.sdf')
     molecule = Molecule.from_file(filename,
                                   toolkit_registry=toolkit_wrapper)
     assert len(molecule._conformers) == 1
     assert molecule._conformers[0].shape == (15, 3)
     assert_almost_equal(molecule.conformers[0][5][1] / unit.angstrom,
                         2.0104,
                         decimal=4)
Пример #7
0
 def test_get_mol2_charges(self):
     """Test OpenEyeToolkitWrapper for importing a mol2 file specifying partial charges"""
     toolkit_wrapper = OpenEyeToolkitWrapper()
     filename = get_data_file_path('molecules/toluene_charged.mol2')
     molecule = Molecule.from_file(filename,
                                   toolkit_registry=toolkit_wrapper)
     assert len(molecule._conformers) == 1
     assert molecule._conformers[0].shape == (15, 3)
     target_charges = unit.Quantity(
         np.array([
             -0.1342, -0.1271, -0.1271, -0.1310, -0.1310, -0.0765, -0.0541,
             0.1314, 0.1286, 0.1286, 0.1303, 0.1303, 0.0440, 0.0440, 0.0440
         ]), unit.elementary_charge)
     for pc1, pc2 in zip(molecule._partial_charges, target_charges):
         pc1_ul = pc1 / unit.elementary_charge
         pc2_ul = pc2 / unit.elementary_charge
         assert_almost_equal(pc1_ul, pc2_ul, decimal=4)
Пример #8
0
    def test_get_mol2_coordinates(self):
        """Test OpenEyeToolkitWrapper for importing a single set of molecule coordinates"""
        toolkit_wrapper = OpenEyeToolkitWrapper()
        filename = get_data_file_path('molecules/toluene.mol2')
        molecule1 = Molecule.from_file(filename,
                                       toolkit_registry=toolkit_wrapper)
        assert len(molecule1._conformers) == 1
        assert molecule1._conformers[0].shape == (15, 3)
        assert_almost_equal(molecule1.conformers[0][5][1] / unit.angstrom,
                            22.98,
                            decimal=2)

        # Test loading from file-like object
        with open(filename, 'r') as infile:
            molecule2 = Molecule(infile,
                                 file_format='MOL2',
                                 toolkit_registry=toolkit_wrapper)
        assert molecule1.is_isomorphic(molecule2)
        assert len(molecule2._conformers) == 1
        assert molecule2._conformers[0].shape == (15, 3)
        assert_almost_equal(molecule2.conformers[0][5][1] / unit.angstrom,
                            22.98,
                            decimal=2)

        # Test loading from gzipped mol2
        import gzip
        with gzip.GzipFile(filename + '.gz', 'r') as infile:
            molecule3 = Molecule(infile,
                                 file_format='MOL2',
                                 toolkit_registry=toolkit_wrapper)
        assert molecule1.is_isomorphic(molecule3)
        assert len(molecule3._conformers) == 1
        assert molecule3._conformers[0].shape == (15, 3)
        assert_almost_equal(molecule3.conformers[0][5][1] / unit.angstrom,
                            22.98,
                            decimal=2)