def test_has_conformer(self): """Test has conformer""" infile = get_fn('butane.pdb') ifs = oechem.oemolistream(infile) molecule_with_conf = oechem.OEMol() oechem.OEReadMolecule(ifs, molecule_with_conf) self.assertTrue(chemi.has_conformer(molecule_with_conf)) molecule_without_conf = chemi.smiles_to_oemol('CCCC') self.assertFalse(chemi.has_conformer(molecule_without_conf))
def test_atom_map(self): """Test get atom map""" from openeye import oechem tagged_smiles = '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]' mol_1 = chemi.smiles_to_oemol('CC[N+]#C') inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = get_atom_map(mol_1, tagged_smiles) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2)) # Test aromatic molecule tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = chemi.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) atom_map = get_atom_map(mol_1, tagged_smiles) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) self.assertEqual(oechem.OECreateCanSmiString(mol_1), oechem.OECreateCanSmiString(mol_2))
def test_generate_torsions(self): """ Tests finding torsion to drive """ from openeye import oechem infile = get_fn('butane.pdb') ifs = oechem.oemolistream(infile) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) needed_torsion_scans = torsions.find_torsions(molecule=inp_mol) self.assertEqual(len(needed_torsion_scans['internal']), 1) self.assertEqual(len(needed_torsion_scans['terminal']), 2) self.assertEqual(needed_torsion_scans['internal']['torsion_0'], (0, 2, 3, 1)) self.assertEqual(needed_torsion_scans['terminal']['torsion_0'], (3, 2, 0, 4)) self.assertEqual(needed_torsion_scans['terminal']['torsion_1'], (2, 3, 1, 7))
def test_tagged_smiles(self): """Test index-tagges smiles""" from openeye import oechem inf = get_fn('ethylmethylidyneamonium.mol2') ifs = oechem.oemolistream(inf) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) tagged_smiles = mol_to_smiles(inp_mol, isomeric=True, mapped=True, explicit_hydrogen=True) # Tags should always be the same as mol2 molecule ordering self.assertEqual( tagged_smiles, '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]')
def test_mapped_xyz(self): """Test writing out mapped xyz""" from openeye import oechem, oeomega tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]' mol_1 = chemi.smiles_to_oemol('Cc1ccccc1') inf = get_fn('toluene.mol2') ifs = oechem.oemolistream(inf) mol_2 = oechem.OEMol() oechem.OEReadMolecule(ifs, mol_2) mol_1 = chemi.generate_conformers(mol_1, max_confs=1) atom_map = get_atom_map(mol_1, tagged_smiles) for i, mapping in enumerate(atom_map): atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping])) atom_1.SetAtomicNum(i + 1) atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1)) atom_2.SetAtomicNum(i + 1) xyz_1 = chemi.to_mapped_xyz(mol_1, atom_map, xyz_format=False) # molecule generated from mol2 should be in the right order. atom_map_mol2 = { 1: 0, 2: 1, 3: 2, 4: 3, 5: 4, 6: 5, 7: 6, 8: 7, 9: 8, 10: 9, 11: 10, 12: 11, 13: 12, 14: 13, 15: 14 } xyz_2 = chemi.to_mapped_xyz(mol_2, atom_map_mol2, xyz_format=False) for ele1, ele2 in zip(xyz_1.split('\n')[:-1], xyz_2.split('\n')[:-1]): self.assertEqual(ele1.split(' ')[2], ele2.split(' ')[2])
def test_workflow(fractal_compute_server): """Fragmenter regression test""" pytest.importorskip("torsiondrive") pytest.importorskip("geometric") pytest.importorskip("rdkit") client = portal.FractalClient(fractal_compute_server) smiles = 'CCCCC' workflow_id = 'example' workflow_json = get_fn('workflows.json') workflow = workflow_api.WorkFlow(client=client, workflow_json=workflow_json, workflow_id=workflow_id) workflow.workflow(molecules_smiles=smiles, molecule_titles=['pentane']) assert len(workflow.qcfractal_jobs) == 1 key = list(workflow.qcfractal_jobs.keys())[0] assert len(workflow.qcfractal_jobs[key]) == 3 assert len(workflow.qcfractal_jobs[key]['optimization_input']) == 0 assert len(workflow.qcfractal_jobs[key]['torsiondrive_input']) == 3 assert len(workflow.qcfractal_jobs[key]['torsiondrive_input'] ['(0, 2, 3, 1)']['initial_molecule']) == 8