Exemplo n.º 1
0
def test_species():

    species = Species(name='species', atoms=None, charge=0, mult=1)
    assert species.n_atoms == 0

    h2 = Species(name='H2', charge=0, mult=1, atoms=[Atom('H'), Atom('H')])
    assert h2.n_atoms == 2

    # Expecting both atoms to be initialised at the origin
    assert np.linalg.norm(h2.atoms[0].coord - h2.atoms[1].coord) < 1E-6

    atom1, atom2 = h2.atoms
    atom1.translate(vec=np.array([1.0, 0.0, 0.0]))
    atom1.rotate(theta=np.pi, axis=np.array([0.0, 0.0, 1.0]))

    assert np.linalg.norm(atom1.coord - np.array([-1., 0., 0.])) < 1E-6

    assert h2.solvent is None

    f = Species(name='F-',
                charge=-1,
                mult=1,
                atoms=[Atom('F')],
                solvent_name='DCM')
    assert f.solvent.g09 == 'Dichloromethane'
    assert f.solvent.xtb == 'CH2Cl2'
Exemplo n.º 2
0
def test_adaptive_path():

    species_no_atoms = Species(name='tmp', charge=0, mult=1, atoms=[])
    path1 = AdaptivePath(init_species=species_no_atoms, bonds=[], method=XTB())
    assert len(path1) == 0
    assert path1.method.name == 'xtb'
    assert len(path1.bonds) == 0

    assert path1 != 0
    assert path1 == path1
Exemplo n.º 3
0
def run_autode(configuration, max_force=None, method=None, n_cores=1):
    """
    Run an orca or xtb calculation

    --------------------------------------------------------------------------
    :param configuration: (gaptrain.configurations.Configuration)

    :param max_force: (float) or None

    :param method: (autode.wrappers.base.ElectronicStructureMethod)
    """
    from autode.species import Species
    from autode.calculation import Calculation
    from autode.exceptions import CouldNotGetProperty

    if method.name == 'orca' and GTConfig.orca_keywords is None:
        raise ValueError("For ORCA training GTConfig.orca_keywords must be"
                         " set. e.g. "
                         "GradientKeywords(['PBE', 'def2-SVP', 'EnGrad'])")

    # optimisation is not implemented, needs a method to run
    assert max_force is None and method is not None

    species = Species(name=configuration.name,
                      atoms=configuration.atoms,
                      charge=configuration.charge,
                      mult=configuration.mult)

    # allow for an ORCA calculation to have non-default keywords.. not the
    # cleanest implementation..
    kwds = GTConfig.orca_keywords if method.name == 'orca' else method.keywords.grad
    calc = Calculation(name='tmp',
                       molecule=species,
                       method=method,
                       keywords=kwds,
                       n_cores=n_cores)
    calc.run()
    ha_to_ev = 27.2114
    try:
        configuration.forces = -ha_to_ev * calc.get_gradients()
    except CouldNotGetProperty:
        logger.error('Failed to set forces')

    configuration.energy = ha_to_ev * calc.get_energy()

    configuration.partial_charges = calc.get_atomic_charges()

    return configuration
Exemplo n.º 4
0
def get_and_copy_unique_confs(xyz_filenames, only_heavy_atoms, threshold_rmsd):
    """For each xyz file generate a species and copy it to a folder if it is
    unique based on an RMSD threshold"""

    molecules = [
        Species(name=fn.rstrip('.xyz'),
                atoms=xyz_file_to_atoms(fn),
                charge=0,
                mult=1) for fn in xyz_filenames
    ]

    if only_heavy_atoms:
        molecules = get_molecules_no_hydrogens(molecules)

    unique_mol_ids = []

    for i in range(len(molecules)):
        mol = molecules[i]

        is_unique = True

        for j in unique_mol_ids:
            rmsd = calc_rmsd(coords1=mol.get_coordinates(),
                             coords2=molecules[j].get_coordinates())

            if rmsd < threshold_rmsd:
                is_unique = False
                break

        if is_unique:
            unique_mol_ids.append(i)

    print('Number of unique molecules = ', len(unique_mol_ids))

    # Copy all the unique .xyz files to a new folder
    if not os.path.exists(folder_name):
        os.mkdir(folder_name)

    for i in unique_mol_ids:
        xyz_filename = xyz_filenames[i]
        copyfile(xyz_filename, os.path.join(folder_name, xyz_filename))

    return None
Exemplo n.º 5
0
def test_pruning_bonds():

    h3 = Species(name='h3',
                 charge=0,
                 mult=2,
                 atoms=[Atom('H'),
                        Atom('H', x=1),
                        Atom('H', x=0.5, y=0.5)])

    fbond = FormingBond(atom_indexes=(0, 1), species=h3)
    bbond1 = BreakingBond(atom_indexes=(0, 2), species=h3)
    bbond2 = BreakingBond(atom_indexes=(1, 2), species=h3)

    new_bonds = pruned_active_bonds(initial_species=h3,
                                    fbonds=[fbond],
                                    bbonds=[bbond1, bbond2])
    assert len(new_bonds) == 2
    # Should prune to one breaking and one forming bond
    assert ((isinstance(new_bonds[0], FormingBond)
             and isinstance(new_bonds[1], BreakingBond))
            or (isinstance(new_bonds[1], FormingBond)
                and isinstance(new_bonds[0], BreakingBond)))
Exemplo n.º 6
0
import os
import numpy as np
from autode.atoms import Atom
from autode.methods import XTB, ORCA
from autode.path import Path, AdaptivePath, PathPoint
from autode.path.adaptive import pruned_active_bonds
from autode.bonds import FormingBond, BreakingBond
from autode.species import Species, Molecule
from autode.units import Unit, KcalMol

test_species = Species(name='tmp', charge=0, mult=1, atoms=[Atom('He')])
test_mol = Molecule(smiles='O')


def test_path_properties_empty():

    path = Path()

    assert len(path) == 0
    assert isinstance(path.units, Unit)

    assert path == Path()  # should be able to compare paths
    assert path != 0

    # With no species there should be no peak/saddle/energies
    assert len(path.rel_energies) == 0
    assert len(path.energies) == 0

    assert not path.contains_peak
    assert path.peak_idx is None
    assert not path.is_saddle(idx=0)