def test_mollist(mols2): bob = BagofBonds(const=1.0, n_jobs=2, verbose=False) for i in mols2: i.hydrogens('remove') features = bob.represent(mols2) assert features.shape == (4, 80) assert bob.header_.count((6.0, 6.0)) == 6
def test_h2o(mols): bob = BagofBonds(const=1.0) h2o = bob.represent(mols) assert h2o.shape == (1, 6) a = np.array([[0.66066557, 0.5, 0.5, 8.3593106, 8.35237809, 73.51669472]]) assert a[0][0] == pytest.approx(h2o.values[0][0]) assert a[0][1] == pytest.approx(h2o.values[0][1]) assert a[0][-1] == pytest.approx(h2o.values[0][-1])
def test_exception(mols): # Value error: molecule object bob = BagofBonds(n_jobs=10) with pytest.raises(ValueError): bob.represent('fake') with pytest.raises(ValueError): bob.represent(['fake']) # Value error ndim>1 with pytest.raises(ValueError): bob.represent(np.array([[mols], [mols]]))
def test_h2o(mols): bob = BagofBonds(const=1.0) h2o_df = bob.represent(mols) assert h2o_df.shape == (1, 6) a = np.array([[0.66066557, 0.5, 0.5, 8.3593106, 8.35237809, 73.51669472]]) # O ind = bob.header_.index((8.0, )) assert a[0][5] == pytest.approx(h2o_df.values[0][ind]) # OH ind = bob.header_.index((8.0, 1.0)) assert a[0][3] == pytest.approx(h2o_df.values[0][ind]) # HH ind = bob.header_.index((1.0, 1.0)) assert a[0][0] == pytest.approx(h2o_df.values[0][ind]) # H ind = bob.header_.index((1.0, )) assert a[0][1] == pytest.approx(h2o_df.values[0][ind])
def bagofbounds(mol2, maxentry): from chemml.chem import Molecule #caffeine_smiles = 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C' #caffeine_smarts = '[#6]-[#7]1:[#6]:[#7]:[#6]2:[#6]:1:[#6](=[#8]):[#7](:[#6](=[#8]):[#7]:2-[#6])-[#6]' #caffeine_inchi = 'InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3' mol = Molecule(Chem.MolToSmiles(mol2), 'smiles') mol.hydrogens('add') mol.to_xyz(optimizer='MMFF', mmffVariant='MMFF94s', maxIters=300) # 'UFF' print(mol) mol.visualize() #mol.visualize() from chemml.datasets import load_xyz_polarizability from chemml.chem import BagofBonds #coordinates, y = load_xyz_polarizability(mol) bob = BagofBonds(const=1.0) features = bob.represent(mol) print(features) print("number of entry") print(features.shape[1]) if features.shape[1] > maxentry: maxentry = features.shape[1] return features, maxentry
from chemml.chem import Molecule caffeine_smiles = 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C' caffeine_smarts = '[#6]-[#7]1:[#6]:[#7]:[#6]2:[#6]:1:[#6](=[#8]):[#7](:[#6](=[#8]):[#7]:2-[#6])-[#6]' caffeine_inchi = 'InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3' mol = Molecule(caffeine_smiles, input_type='smiles') mol.hydrogens('add') mol.to_xyz(optimizer='MMFF', mmffVariant='MMFF94s', maxIters=300) # 'UFF' print(mol) mol.visualize() #mol.visualize() from chemml.datasets import load_xyz_polarizability from chemml.chem import BagofBonds #coordinates, y = load_xyz_polarizability(mol) bob = BagofBonds(const= 1.0) features = bob.represent(mol) print(features)
import chemml from chemml.datasets import load_xyz_polarizability from chemml.chem import BagofBonds coordinates, y = load_xyz_polarizability() bob = BagofBonds(const=1.0) features = bob.represent(coordinates)
def test_mollist(mols2): bob = BagofBonds(const=1.0, n_jobs=2, verbose=False) features = bob.represent(mols2) assert features.shape == (4, 13) assert bob.header_.count((6.0,6.0)) == 6