コード例 #1
0
def test_solvent_get():
    xtb = XTB()

    # Can't get the name of a solvent if molecule.solvent is not a string
    test_mol.solvent = 5
    with pytest.raises(ex.SolventUnavailable):
        _ = get_solvent_name(molecule=test_mol, method=xtb)

    test_mol.solvent = None
    assert get_solvent_name(test_mol, method=xtb) is None

    test_mol.solvent = 'a_solvent_that_doesnt_exist'
    with pytest.raises(ex.SolventNotFound):
        _ = get_solvent_name(molecule=test_mol, method=xtb)

    # Should work fine with a normal solvent
    test_mol.solvent = get_solvent(solvent_name='water')
    solv_name_xtb = get_solvent_name(test_mol, method=xtb)
    assert solv_name_xtb.lower() in ['water', 'h2o']

    # Currently iodoethane is not in XTB - might be in the future
    test_mol.solvent = get_solvent(solvent_name='iodoethane')
    with pytest.raises(ex.SolventUnavailable):
        _ = get_solvent_name(test_mol, method=xtb)

    test_mol.solvent = 0
    with pytest.raises(ex.SolventUnavailable):
        _ = get_solvent_name(test_mol, method=xtb)

    # return to the gas phase
    test_mol.solvent = None
コード例 #2
0
ファイル: test_solvents.py プロジェクト: t-young31/autodE
def test_get_solvent():

    water = solvents.get_solvent(solvent_name='water')
    assert water.name == 'water'
    assert water.smiles == 'O'

    with pytest.raises(SolventNotFound):
        solvents.get_solvent(solvent_name='test_solvent')
コード例 #3
0
ファイル: species.py プロジェクト: t-young31/autodE
    def __init__(self, name, atoms, charge, mult, solvent_name=None):
        """
        A molecular species. A collection of atoms with a charge and spin
        multiplicity in a solvent (None is gas phase)

        Arguments:
            name (str): Name of the species
            atoms (list(autode.atoms.Atom)): List of atoms in the species,
                                              or None
            charge (int): Charge on the species
            mult (int): Spin multiplicity of the species. 2S+1, where S is the
                        number of unpaired electrons

        Keyword Arguments:
            solvent_name (str): Name of the solvent_name, or None
        """
        self.name = name

        self.atoms = atoms
        self.n_atoms = 0 if atoms is None else len(atoms)
        self.charge = int(charge)
        self.mult = int(mult)

        self.solvent = get_solvent(solvent_name=solvent_name)

        self.energy = None        # Total electronic energy in Hartrees (float)

        self.graph = None         # NetworkX.Graph object with atoms and bonds

        self.conformers = None    # List autode.conformers.conformers.Conformer
コード例 #4
0
def get_solvent_name(molecule, method):
    """
    Set the solvent keyword to use in the calculation given an QM method

    Arguments:
        molecule (autode.species.Species)
        method (autode.wrappers.base.ElectronicStructureMethod):
    """

    if molecule.solvent is None:
        logger.info('Calculation is in the gas phase')
        return None

    if type(molecule.solvent) is str:
        # Solvent could be a string from e.g. cgbind
        solvent = get_solvent(solvent_name=molecule.solvent)

    elif isinstance(molecule.solvent, Solvent):
        # Otherwise expecting a autode.solvents.solvent.Solvent
        solvent = molecule.solvent

    else:
        raise ex.SolventUnavailable('Expecting either a str or Solvent')

    try:
        # Get the name of the solvent for this method
        return getattr(solvent, method.name)

    except AttributeError:
        raise ex.SolventUnavailable(f'Available solvents for {method.name} are'
                                    f' {get_available_solvent_names(method)}')
コード例 #5
0
ファイル: reaction.py プロジェクト: gabegomes/autodE
    def __init__(self,
                 *args,
                 name='reaction',
                 solvent_name=None,
                 smiles=None,
                 temp=298.15):
        """
        Reaction containing reactants and products. reaction.reactant is the
        reactant complex which is the same as reacs[0] if there is only
        reactant

        Arguments:
             args (autode.species.Molecule) or (str): Reactant and Product
                  objects or a SMILES string of the whole reaction

            name (str):

            solvent_name (str):

            smiles (str):

            temp (float): Temperature in Kelvin
        """
        logger.info(f'Generating a Reaction object for {name}')

        self.name = name
        self.reacs = [mol for mol in args if isinstance(mol, Reactant)]
        self.prods = [mol for mol in args if isinstance(mol, Product)]

        # If there is only one string argument assume it's a SMILES
        if len(args) == 1 and type(args[0]) is str:
            smiles = args[0]

        if smiles is not None:
            self._init_from_smiles(smiles)

        self.reactant, self.product = None, None
        self.ts, self.tss = None, None

        self.type = reaction_types.classify(self.reacs, self.prods)
        self.solvent = get_solvent(solvent_name=solvent_name)
        self.temp = float(temp)

        self._check_solvent()
        self._check_balance()
コード例 #6
0
    def load(self, filename):
        """
        Load a template from a saved file

        Arguments:
            filename (str):

        Raise:
            (autode.exceptions.TemplateLoadingFailed):
        """
        try:
            template_lines = open(filename, 'r').readlines()
        except (IOError, UnicodeDecodeError):
            raise TemplateLoadingFailed('Failed to read file lines')

        if len(template_lines) < 5:
            raise TemplateLoadingFailed('Not enough lines in the template')

        name = get_value_from_file('solvent', template_lines)

        if name.lower() == 'none':
            self.solvent = None
        else:
            self.solvent = get_solvent(solvent_name=name)

        self.charge = int(get_value_from_file('charge', template_lines))
        self.mult = int(get_value_from_file('multiplicity', template_lines))

        # Set the template graph by adding nodes and edges with atoms labels
        # and active/pi/distance attributes respectively
        self.graph = nx.Graph()

        nodes = get_values_dict_from_file('nodes', template_lines)
        for idx, data in nodes.items():
            self.graph.add_node(idx, **data)

        edges = get_values_dict_from_file('edges', template_lines)

        for pair, data in edges.items():
            self.graph.add_edge(*pair, **data)

        if not self.graph_has_correct_structure():
            raise TemplateLoadingFailed('Incorrect graph structure')

        return None
コード例 #7
0
def test_get_explicit_solvent():
    # Implement explicit solvent test here..

    with pytest.raises(NotImplementedError):
        _ = get_solvent(solvent_name='water', explicit=True)