Пример #1
0
def test_manipulation():
    methane = Molecule(name='CH4', smiles='C')
    assert methane.n_atoms == 5
    ch3_nodes, h_nodes = split_mol_across_bond(methane.graph, bond=(0, 1))

    ch3 = Molecule(name='CH3',
                   mult=2,
                   atoms=[methane.atoms[i] for i in ch3_nodes])
    assert ch3.n_atoms == 4

    h = Molecule(name='H', mult=2, atoms=[methane.atoms[i] for i in h_nodes])
    assert h.n_atoms == 1
Пример #2
0
def test_molecule():

    molecule = Molecule(name='molecule')
    assert molecule.charge == 0
    assert molecule.mult == 1

    water = Molecule(name='h2o', smiles='O')
    assert water.n_atoms == 3
    assert all(node in water.graph.nodes for node in (0, 1, 2))
    assert (0, 1) in water.graph.edges
    assert (0, 2) in water.graph.edges

    # Shift so the first atom is at the origin
    water.translate(vec=-water.atoms[0].coord)
    assert np.linalg.norm(water.atoms[0].coord - np.zeros(3)) < 1E-6
Пример #3
0
def test_conformers(tmpdir):
    os.chdir(tmpdir)

    butane = Molecule(name='butane', smiles='CCCC')
    butane.populate_conformers(n_confs=10)

    n_confs = len(butane.conformers)
    assert n_confs > 1

    # Lowing the RMSD threshold should afford more conformers
    Config.rmsd_threshold = 0.01
    butane.populate_conformers(n_confs=10)
    assert len(butane.conformers) > n_confs

    # Conformer generation should also work if the RDKit method fails
    butane.rdkit_conf_gen_is_fine = False
    butane.populate_conformers(n_confs=10)
    assert len(butane.conformers) > 1

    # Change RMSD threshold back
    Config.rmsd_threshold = 0.3

    os.chdir(here)
Пример #4
0
def test_sp_hmethod_ranking():

    Config.hmethod_sp_conformers = True

    butane = Molecule(smiles='CCCC')
    xtb = XTB()
    cwd = os.getcwd()

    # Need to set hmethod.low_sp
    with pytest.raises(AssertionError):
        butane.find_lowest_energy_conformer(lmethod=xtb, hmethod=orca)

    # work_in function will change directories and not change back when an
    # exception is raised, so ensure we're working in the same dir as before
    os.chdir(cwd)

    orca.keywords.low_sp = SinglePointKeywords(['PBE', 'D3BJ', 'def2-SVP'])
    butane.find_lowest_energy_conformer(lmethod=xtb, hmethod=orca)
    assert butane.energy is not None

    Config.hmethod_sp_conformers = False
Пример #5
0
def test_calc_class():

    xtb = XTB()

    calc = Calculation(name='-tmp',
                       molecule=test_mol,
                       method=xtb,
                       keywords=xtb.keywords.sp)

    # Should prepend a dash to appease some EST methods
    assert not calc.name.startswith('-')
    assert calc.molecule is not None
    assert calc.method.name == 'xtb'

    assert calc.get_energy() is None
    assert calc.get_enthalpy() is None
    assert calc.get_free_energy() is None

    assert not calc.optimisation_converged()
    assert not calc.optimisation_nearly_converged()

    with pytest.raises(ex.AtomsNotFound):
        _ = calc.get_final_atoms()

    with pytest.raises(ex.CouldNotGetProperty):
        _ = calc.get_gradients()

    with pytest.raises(ex.CouldNotGetProperty):
        _ = calc.get_atomic_charges()

    # Calculation that has not been run shouldn't have an opt converged
    assert not calc.optimisation_converged()
    assert not calc.optimisation_nearly_converged()

    # With a filename that doesn't exist a NoOutput exception should be raised
    calc.output.filename = '/a/path/that/does/not/exist/tmp'
    with pytest.raises(ex.NoCalculationOutput):
        calc.output.set_lines()

    # With no output should not be able to get properties
    calc.output.filename = 'tmp'
    calc.output.file_lines = []
    with pytest.raises(ex.CouldNotGetProperty):
        _ = calc.get_atomic_charges()

    # or final atoms
    with pytest.raises(ex.AtomsNotFound):
        _ = calc.get_final_atoms()

    # Should default to a single core
    assert calc.n_cores == 1

    calc_str = str(calc)
    new_calc = Calculation(name='tmp2',
                           molecule=test_mol,
                           method=xtb,
                           keywords=xtb.keywords.sp)
    new_calc_str = str(new_calc)
    # Calculation strings need to be unique
    assert new_calc_str != calc_str

    new_calc = Calculation(name='tmp2',
                           molecule=test_mol,
                           method=xtb,
                           keywords=xtb.keywords.sp,
                           temp=5000)
    assert str(new_calc) != new_calc_str

    mol_no_atoms = Molecule()
    with pytest.raises(ex.NoInputError):
        _ = Calculation(name='tmp2',
                        molecule=mol_no_atoms,
                        method=xtb,
                        keywords=xtb.keywords.sp)
Пример #6
0
from autode.calculation import Calculation, get_solvent_name
from autode.solvent.solvents import get_solvent
from autode.wrappers.keywords import SinglePointKeywords
from autode.wrappers.functionals import Functional
from autode.methods import XTB, ORCA
from autode.species import Molecule
from autode.config import Config
import autode.exceptions as ex
from autode.utils import work_in_tmp_dir
import pytest
import os

test_mol = Molecule(smiles='O', name='test_mol')


def test_calc_class():

    xtb = XTB()

    calc = Calculation(name='-tmp',
                       molecule=test_mol,
                       method=xtb,
                       keywords=xtb.keywords.sp)

    # Should prepend a dash to appease some EST methods
    assert not calc.name.startswith('-')
    assert calc.molecule is not None
    assert calc.method.name == 'xtb'

    assert calc.get_energy() is None
    assert calc.get_enthalpy() is None
Пример #7
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)