How to use the ase.calculators.calculator.Calculator function in ase

To help you get started, we’ve selected a few ase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jkitchin / vasp / vasp / vasp.py View on Github external
else:
        inner.__doc__ = 'Wrapped in vasp.tryit.'
    return inner

from ase.calculators.calculator import Calculator,\
    FileIOCalculator

import inspect

# We avoid decorating class methods. It seems to break them.
for attr in Vasp.__dict__:
    f = getattr(Vasp, attr)
    if inspect.ismethod(f) and f.__self__ is not Vasp:
        setattr(Vasp, attr, tryit(getattr(Vasp, attr)))

for attr in Calculator.__dict__:
    f = getattr(Vasp, attr)
    if inspect.ismethod(f) and f.__self__ is not Vasp:
        setattr(Calculator, attr, tryit(getattr(Calculator, attr)))

for attr in FileIOCalculator.__dict__:
    f = getattr(Vasp, attr)
    if inspect.ismethod(f) and f.__self__ is not Vasp:
        setattr(FileIOCalculator, attr,
                tryit(getattr(FileIOCalculator, attr)))
github pyscf / pyscf / pbc / tools / pyscf_ase.py View on Github external
'''

import numpy as np
from ase.calculators.calculator import Calculator
import ase.dft.kpoints
from ase.lattice import bulk

def ase_atoms_to_pyscf(ase_atoms):
    '''Convert ASE atoms to PySCF atom.

    Note: ASE atoms always use A.
    '''
    return [[atom.symbol, atom.position] for atom in ase_atoms]
atoms_from_ase = ase_atoms_to_pyscf

class PySCF(Calculator):
    implemented_properties = ['energy']

    def __init__(self, restart=None, ignore_bad_restart_file=False,
                 label='PySCF', atoms=None, scratch=None, **kwargs):
        """Construct PySCF-calculator object.

        Parameters
        ==========
        label: str
            Prefix to use for filenames (label.in, label.txt, ...).
            Default is 'PySCF'.

        mfclass: PySCF mean-field class
        molcell: PySCF :Mole: or :Cell:
        """
        Calculator.__init__(self, restart=None, ignore_bad_restart_file=False,
github SUNCAT-Center / CatalysisHubBackend / models.py View on Github external
charges=self.initial_charges,
                                tags=self.tags,
                                masses=self.masses,
                                momenta=self.momenta,
                                constraint=constraints)
        atoms.info = {}
        atoms.info['unique_id'] = self.unique_id
        atoms.info['key_value_pairs'] = self.key_value_pairs

        data = self.data
        if data:
            atoms.info['data'] = data

        if not self.calculator == "unknown":
            params = self.calculator_parameters
            atoms.calc = Calculator(self.calculator, **params)
            atoms.calc.name = self.calculator
        else:
            all_properties = ['energy', 'forces', 'stress', 'dipole',
                              'charges', 'magmom', 'magmoms', 'free_energy']
            results = {}
            for prop in all_properties:
                result = getattr(self, prop, None)
                if result is not None:
                    results[prop] = result
            if results:
                atoms.calc = SinglePointCalculator(atoms, **results)
                atoms.calc.name = getattr(self, 'calculator', 'unknown')
        return atoms
github aiqm / torchani / torchani / ase.py View on Github external
"""Tools for interfacing with `ASE`_.

.. _ASE:
    https://wiki.fysik.dtu.dk/ase
"""

import torch
from .nn import Sequential
import ase.neighborlist
from . import utils
import ase.calculators.calculator
import ase.units
import copy


class Calculator(ase.calculators.calculator.Calculator):
    """TorchANI calculator for ASE

    Arguments:
        species (:class:`collections.abc.Sequence` of :class:`str`):
            sequence of all supported species, in order.
        aev_computer (:class:`torchani.AEVComputer`): AEV computer.
        model (:class:`torchani.ANIModel` or :class:`torchani.Ensemble`):
            neural network potential models.
        energy_shifter (:class:`torchani.EnergyShifter`): Energy shifter.
        dtype (:class:`torchani.EnergyShifter`): data type to use,
            by dafault ``torch.float64``.
        overwrite (bool): After wrapping atoms into central box, whether
            to replace the original positions stored in :class:`ase.Atoms`
            object with the wrapped positions.
    """
github rosswhitfield / ase / ase / neb.py View on Github external
for atoms in self.images:
                yield atoms
            return

        for i, atoms in enumerate(self.images):
            if i == 0 or i == self.nimages - 1:
                yield atoms
            else:
                atoms = atoms.copy()
                atoms.calc = SinglePointCalculator(energy=self.energies[i],
                                                   forces=self.real_forces[i],
                                                   atoms=atoms)
                yield atoms


class IDPP(Calculator):
    """Image dependent pair potential.

    See:
        Improved initial guess for minimum energy path calculations.
        Søren Smidstrup, Andreas Pedersen, Kurt Stokbro and Hannes Jónsson
        Chem. Phys. 140, 214106 (2014)
    """

    implemented_properties = ['energy', 'forces']

    def __init__(self, target, mic):
        Calculator.__init__(self)
        self.target = target
        self.mic = mic

    def calculate(self, atoms, properties, system_changes):
github libAtoms / matscipy / matscipy / socketcalc.py View on Github external
_chdir_lock.acquire()
            os.chdir(self.subdir)
            cellf = open('castep.cell', 'w')
            write_castep_cell(cellf, at, castep_cell=self.castep.cell)
            cellf.close()
            write_param('castep.param', self.castep.param, force_write=True)

        finally:
            os.chdir(orig_dir)
            _chdir_lock.release()

    def extra_args(self, label=None):
        return ['castep']


class SocketCalculator(Calculator):
    """
    ASE-compatible calculator which communicates with remote
    force engines via sockets using a (synchronous) AtomsServer.
    """

    implemented_properties = ['energy', 'forces', 'stress']
    default_parameters = {}
    name = 'SocketCalculator'

    def __init__(self, client, ip=None, atoms=None, port=0, logger=screen, bgq=False):
        Calculator.__init__(self)

        self.client = client
        if ip is None:
            ip = '127.0.0.1' # default to localhost
        self.logger = logger
github isayev / ASE_ANI / ani.py View on Github external
def __init__(self, **kwargs):
        Calculator.__init__(self, **kwargs)
github rosswhitfield / ase / ase / calculators / lammpsrun.py View on Github external
from ase.parallel import paropen
from ase.calculators.calculator import Calculator
from ase.calculators.calculator import all_changes
from ase.data import chemical_symbols
from ase.data import atomic_masses
from ase.io.lammpsdata import write_lammps_data
from ase.io.lammpsrun import read_lammps_dump
from ase.calculators.lammps import Prism
from ase.calculators.lammps import write_lammps_in
from ase.calculators.lammps import CALCULATION_END_MARK
from ase.calculators.lammps import convert

__all__ = ["LAMMPS"]


class LAMMPS(Calculator):
    """The LAMMPS calculators object

    files: list
        List of files typically containing relevant potentials for the calculation
    parameters: dict
        Dictionary of settings to be passed into the input file for calculation.
    specorder: list
        Within LAAMPS, atoms are identified by an integer value starting from 1.
        This variable allows the user to define the order of the indices assigned to the
        atoms in the calculation, with the default if not given being alphabetical
    keep_tmp_files: bool
        Retain any temporary files created. Mostly useful for debugging.
    tmp_dir: str
        path/dirname (default None -> create automatically).
        Explicitly control where the calculator object should create
        its files. Using this option implies 'keep_tmp_files'
github rosswhitfield / ase / ase / optimize / activelearning / gp / calculator.py View on Github external
import numpy as np
import warnings
from ase.optimize.activelearning.gp.kernel import SquaredExponential
from ase.optimize.activelearning.gp.gp import GaussianProcess
from ase.optimize.activelearning.gp.prior import ConstantPrior
from ase.calculators.calculator import Calculator, all_changes
from scipy.linalg import solve_triangular
from scipy.spatial.distance import euclidean


class GPCalculator(Calculator, GaussianProcess):
    """
    GP model parameters
    -------------------
    train_images: list
        List of Atoms objects containing the observations which will be use
        to train the model.

    prior: Prior object or None
        Prior for the GP regression of the PES surface. See
        ase.optimize.activelearning.prior. If *Prior* is None, then it is set
        as the ConstantPrior with the constant being updated using the
        update_prior_strategy specified as a parameter.

    weight: float
        Pre-exponential factor of the Squared Exponential kernel. If
        *update_hyperparams* is False, changing this parameter has no effect