Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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[*]')
Exemple #4
0
def test_bad_core_molecule():

    atoms_far_h = [Atom('C', 1.24788, 0.56457, -1.79703),
                   Atom('H', 9, 9, 9),
                   Atom('H', 0.87808, 0.86789, -2.79804),
                   Atom('H', 0.87807, 1.27982, -1.03385),
                   Atom('H', 0.87807, -0.45398, -1.55920)]

    # Core molecule with a atom to delete that doesn't have a nearest neighbour
    core_mol = CoreMolecule(atoms=atoms_far_h)

    with pytest.raises(DatomsNotValid):
        core_mol.get_datom_nn(datom_idx=1)
Exemple #5
0
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[*]'])
Exemple #6
0
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())
Exemple #7
0
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
Exemple #8
0
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())
Exemple #9
0
def test_core_molecule():

    core_mol = CoreMolecule(atoms=atoms)
    # Core molecule with no atoms to delete should retain all atoms
    assert core_mol.n_atoms == 5

    core_mol = CoreMolecule(atoms=atoms, atoms_to_del=[2])
    assert core_mol.n_atoms == 4

    # atoms_to_del list is indexed from 1, so atom 0 is not valid
    with pytest.raises(DatomsNotValid):
        _ = CoreMolecule(atoms=atoms, atoms_to_del=[0])

    with pytest.raises(DatomsNotValid):
        _ = CoreMolecule(atoms=atoms, atoms_to_del=[6])

    # Cannot use a carbon atom in ethane as the atom to delete
    xyz_path = os.path.join(here, 'data', 'ethane.xyz')

    with pytest.raises(DatomsNotValid):
        _ = CoreMolecule(name='ethane', xyz_filename=xyz_path, atoms_to_del=[1])
Exemple #10
0
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
Exemple #11
0
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())
Exemple #12
0
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
Exemple #13
0
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
Exemple #14
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())
Exemple #15
0
def test_combined_molecule_no_core():

    core_mol = CoreMolecule(atoms=atoms)

    with pytest.raises(CombinationFailed):
        _ = CombinedMolecule(core_mol=core_mol, frag_smiles='C[*]')
Exemple #16
0
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()