def test_pme3(): ph3 = CoreMolecule(xyz_filename=os.path.join(here, 'data', 'PH3.xyz'), atoms_to_del=[2, 3, 4]) pme3 = CombinedMolecule(core_mol=ph3, frag_smiles='C[*]', name='PMe3') assert coordinates_are_resonable(coords=pme3.get_coordinates())
def test_benzene_func(): benzene_xyz_path = os.path.join(here, 'data', 'benzene.xyz') # Every hydrogen atom in benzene should be able to be functionalised for atom_to_del in [7, 8, 9, 10, 11, 12]: benzene = CoreMolecule(name='benzene', xyz_filename=benzene_xyz_path, atoms_to_del=[atom_to_del]) toluene = CombinedMolecule(benzene, frag_smiles='C[*]') assert toluene.n_atoms == 15 # Likewise if the atoms are reordered so the H atoms are first benzene_xyz_path = os.path.join(here, 'data', 'benzene_reordered.xyz') for atom_to_del in [1, 2, 3, 4, 5, 6]: benzene = CoreMolecule(name='benzene', xyz_filename=benzene_xyz_path, atoms_to_del=[atom_to_del]) toluene = CombinedMolecule(benzene, frag_smiles='C[*]') assert toluene.n_atoms == 15
def test_combined_molecule_ortho_subst(): methane = CoreMolecule(atoms=atoms, atoms_to_del=[2, 3]) # Submitting two tBu groups onto methane should be possible (generate a # sensible structure if the optimisation includes the previously added # fragment subt = CombinedMolecule(core_mol=methane, frag_smiles='CC(C)([*])C') assert coordinates_are_resonable(coords=subt.get_coordinates())
def test_tpp(): for name in ['Ph', 'phenyl', 'C6H5']: ph3 = CoreMolecule(xyz_filename='examples/PH3.xyz', atoms_to_del=[2, 3, 4]) # Fragments are added with aliases so any of {Ph, pheynl, C5H6} are # possible fragment = get_fragment_molecule(name=name) assert fragment is not None tpp = CombinedMolecule(core_mol=ph3, fragment=fragment, name='TPP') assert coordinates_are_resonable(coords=tpp.get_coordinates()) assert tpp.n_atoms == 34
def test_fragment_from_file(): benzene = CoreMolecule(xyz_filename=os.path.join(here, 'data', 'benzene.xyz'), atoms_to_del=[7]) methyl = FragmentMolecule(name='methyl', xyz_filename=os.path.join( here, 'data', 'methyl.xyz')) toluene = CombinedMolecule(core_mol=benzene, fragment=methyl, name='toluene') assert toluene.n_atoms == 15 assert coordinates_are_resonable(coords=toluene.get_coordinates())
def test_combined_molecule_diff_fragements(): core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2]) # Can't add two fragments to a molecule with one atom to delete with pytest.raises(CombinationFailed): _ = CombinedMolecule(core_mol=core_mol, frag_smiles_list=['C[*]', 'C[*]']) # Similarly with two atoms to delete and a fragment smiles list of only # one fragment core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2, 3]) with pytest.raises(CombinationFailed): _ = CombinedMolecule(core_mol=core_mol, frag_smiles_list=['C[*]'])
def test_dmhp(): ph3 = CoreMolecule(xyz_filename=os.path.join(here, 'data', 'PH3.xyz'), atoms_to_del=[2, 3, 4]) dimphp = CombinedMolecule( core_mol=ph3, frag_smiles_list=['C[*]', 'C[*]', '[*]C1=CC=CC=C1'], name='dimphp') # Check that the geometry is fairly sensible assert coordinates_are_resonable(coords=dimphp.get_coordinates()) dimphp.make_graph() assert dimphp.graph.number_of_edges() == 20
def test_example(): benzene_file_path = os.path.join(here, 'data', 'benzene.xyz') benzene = CoreMolecule(xyz_filename=benzene_file_path, atoms_to_del=[7]) toluene = CombinedMolecule(core_mol=benzene, frag_smiles='C[*]', name='toluene') toluene.print_xyz_file() assert os.path.exists('toluene.xyz') gen_toluene_atoms = xyz_file_to_atoms('toluene.xyz') os.remove('toluene.xyz') # Toluene has 15 atoms assert len(gen_toluene_atoms) == 15
def test_combined_molecule_no_nn(): methane = CoreMolecule(atoms=atoms) methane.datom_idxs = [2] with pytest.raises(CombinationFailed): _ = CombinedMolecule(core_mol=methane, frag_smiles='C[*]')
def test_combined_molecule_no_fragments(): core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2]) # Should be able to make a combined molecule from a core that has no # atoms to delete, but will add no atoms (Is this the clearest behaviour?) mol = CombinedMolecule(core_mol=core_mol) assert mol.n_atoms == 0
def test_fragment_molecule2(): core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2]) # Fragment molecules can also be initialised from [Fr] SMILES strings as # well as ['*'] fragment_mol = FragmentMolecule(name='HOR', smiles='O[*]') assert fragment_mol.n_atoms == 2 # OH atoms mol = CombinedMolecule(core_mol=core_mol, fragment=fragment_mol) assert mol.n_atoms == 6 assert coordinates_are_resonable(coords=mol.get_coordinates()) # Should also work directly from the SMILES string mol = CombinedMolecule(core_mol=core_mol, frag_smiles='O[*]') assert mol.n_atoms == 6 assert coordinates_are_resonable(coords=mol.get_coordinates())
def test_combined_molecule_no_core(): core_mol = CoreMolecule(atoms=atoms) with pytest.raises(CombinationFailed): _ = CombinedMolecule(core_mol=core_mol, frag_smiles='C[*]')
def test_combined_molecule(): core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2]) # Ethane mol = CombinedMolecule(core_mol=core_mol, frag_smiles='C[*]') assert coordinates_are_resonable(coords=mol.get_coordinates()) assert mol.n_atoms == 8 mol = CombinedMolecule(core_mol=core_mol, frag_smiles_list=['C[*]']) assert coordinates_are_resonable(coords=mol.get_coordinates()) assert mol.n_atoms == 8 fragment_mol = FragmentMolecule(smiles='C[*]') mol = CombinedMolecule(core_mol=core_mol, fragment=fragment_mol) assert coordinates_are_resonable(coords=mol.get_coordinates()) assert mol.n_atoms == 8 mol = CombinedMolecule(core_mol=core_mol, fragments=[fragment_mol]) assert coordinates_are_resonable(coords=mol.get_coordinates()) assert mol.n_atoms == 8 # Delete two hydrogens from methae core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2, 3]) # Propane mol = CombinedMolecule(core_mol=core_mol, frag_smiles='C[*]') assert coordinates_are_resonable(coords=mol.get_coordinates()) assert mol.n_atoms == 11
from molfunc import CoreMolecule, CombinedMolecule fragments = { 'NMe2': 'CN([Fr])C', 'NH2': 'N[Fr]', 'OH': 'O[Fr]', 'Me': 'C[Fr]', 'F': 'F[Fr]' } methane = CoreMolecule(xyz_filename='CH4.xyz', atoms_to_del=[2]) for name, smiles in fragments.items(): combined = CombinedMolecule(core_mol=methane, frag_smiles=smiles, name=f'CH3_{name}') combined.print_xyz_file()