How to use the ase.calculators.calculator.Calculator.calculate 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 rosswhitfield / ase / ase / calculators / checkpoint.py View on Github external
def calculate(self, atoms, properties, system_changes):
        Calculator.calculate(self, atoms, properties, system_changes)
        try:
            results = self.checkpoint.load(atoms)
            prev_atoms, results = results[0], results[1:]
            try:
                assert atoms_almost_equal(atoms, prev_atoms)
            except AssertionError:
                raise AssertionError('mismatch between current atoms and '
                                     'those read from checkpoint file')
            self.logfile.write('retrieved results for {0} from checkpoint\n'
                               .format(properties))
            # save results in calculator for next time
            if isinstance(self.calculator, Calculator):
                if not hasattr(self.calculator, 'results'):
                    self.calculator.results = {}
                self.calculator.results.update(dict(zip(properties, results)))
        except NoCheckpoint:
github libAtoms / matscipy / matscipy / calculators / mcfm / calculator.py View on Github external
Parameters
        ----------
        atoms : ASE.atoms
            atoms object
        properties : list
            properties ot evaluate
        system_changes : TYPE
            changes in the system

        Raises
        ------
        AttributeError
            Must provide an atoms object
        """

        Calculator.calculate(self, atoms=atoms, properties=properties, system_changes=system_changes)
        # Check for atoms and if present wrap them to their cell
        if atoms is None:
            raise AttributeError("No atoms object provided")
        else:
            pass

        self.print_message("\nCalculation with MCFM potential!", limit=10)
        self.print_message("Calculating parameters using classical potential", limit=10)
        forces, potential_energy, potential_energies =\
            self.produce_classical_results(atoms=atoms)

        self.results["classical_forces"] = forces.copy()

        self.print_message(
            "Update the qm_cluster based on potential energies obtained from mm_pot calculation", limit=10)
github libAtoms / matscipy / matscipy / checkpoint.py View on Github external
def calculate(self, atoms, properties, system_changes):
        Calculator.calculate(self, atoms, properties, system_changes)
        if system_changes:
            with connect(self.db) as db:
                db.write(atoms, checkpoint_id=self.id)
            self.id += 1

            dummy_results = {'energy': 0.0,
                             'forces': np.zeros((len(atoms), 3)),
                             'stress': np.zeros((3,3))}
            self.results = {}
            for key in properties:
                self.results[key] = dummy_results[key]
github rosswhitfield / ase / ase / calculators / mixed.py View on Github external
def calculate(self, atoms=None, properties=['energy'],
                  system_changes=all_changes):
        Calculator.calculate(self, atoms, properties, system_changes)

        for prop in properties:
            atoms_tmp = self.atoms.copy()
            prop1 = self.calc1.get_property(prop, atoms_tmp)
            atoms_tmp = self.atoms.copy()
            prop2 = self.calc2.get_property(prop, atoms_tmp)
            self.results[prop] = self.weight1 * prop1 + self.weight2 * prop2

            if prop == 'energy':
                self.results['energy_contributions'] = (prop1, prop2)
github rosswhitfield / ase / ase / calculators / openmx / openmx.py View on Github external
"""
        Capture the RuntimeError from FileIOCalculator.calculate
        and  add a little debug information from the OpenMX output.
        See base FileIOCalculator for documentation.
        """
        if self.parameters.data_path is None:
            if not 'OPENMX_DFT_DATA_PATH' in os.environ:
                warnings.warn('Please either set OPENMX_DFT_DATA_PATH as an'
                              'enviroment variable or specify dft_data_path as'
                              'a keyword argument')

        self.prind("Start Calculation")
        if properties is None:
            properties = self.implemented_properties
        try:
            Calculator.calculate(self, atoms, properties, system_changes)
            self.write_input(atoms=self.atoms, parameters=self.parameters,
                             properties=properties,
                             system_changes=system_changes)
            self.print_input(debug=self.debug, nohup=self.nohup)
            self.run()
            #  self.read_results()
            self.version = self.read_version()
            output_atoms = read_openmx(filename=self.label, debug=self.debug)
            self.output_atoms = output_atoms
            # XXX The parameters are supposedly inputs, so it is dangerous
            # to update them from the outputs. --askhl
            self.parameters.update(output_atoms.calc.parameters)
            self.results = output_atoms.calc.results
            # self.clean()
        except RuntimeError as e:
            try:
github rosswhitfield / ase / ase / calculators / ff.py View on Github external
def calculate(self, atoms, properties, system_changes):
        Calculator.calculate(self, atoms, properties, system_changes)
        if system_changes:
            for name in ['energy', 'forces', 'hessian']:
                self.results.pop(name, None)
        if 'energy' not in self.results:
            energy = 0.0
            for morse in self.morses:
                i, j, e = ff.get_morse_potential_value(atoms, morse)
                energy += e
            for bond in self.bonds:
                i, j, e = ff.get_bond_potential_value(atoms, bond)
                energy += e
            for angle in self.angles:
                i, j, k, e = ff.get_angle_potential_value(atoms, angle)
                energy += e
            for dihedral in self.dihedrals:
                i, j, k, l, e = ff.get_dihedral_potential_value(
github rosswhitfield / ase / ase / calculators / kim / kimmodel.py View on Github external
Parameters
        ----------
        atoms : Atoms
            Atoms object whose properties are desired

        properties : list of str
            List of what needs to be calculated.  Can be any combination
            of 'energy', 'forces' and 'stress'.

        system_changes : list of str
            List of what has changed since last calculation.  Can be any
            combination of these six: 'positions', 'numbers', 'cell',
            and 'pbc'.
        """

        Calculator.calculate(self, atoms, properties, system_changes)

        # Update KIM API input data and neighbor list, if necessary
        if system_changes:
            if self.need_neigh_update(atoms, system_changes):
                self.update_neigh(atoms, self.species_map)
                self.energy = np.array([0.0], dtype=np.double)
                self.forces = np.zeros([self.num_particles[0], 3], dtype=np.double)
                self.update_compute_args_pointers(self.energy, self.forces)
            else:
                self.update_kim_coords(atoms)

            self.kim_model.compute(self.compute_args, self.release_GIL)

        energy = self.energy[0]
        forces = self.assemble_padding_forces()
github rosswhitfield / ase / ase / calculators / morse.py View on Github external
def calculate(self, atoms=None, properties=['energy'],
                  system_changes=['positions', 'numbers', 'cell',
                                  'pbc', 'charges', 'magmoms']):
        Calculator.calculate(self, atoms, properties, system_changes)
        epsilon = self.parameters.epsilon
        rho0 = self.parameters.rho0
        r0 = self.parameters.r0
        positions = self.atoms.get_positions()
        energy = 0.0
        forces = np.zeros((len(self.atoms), 3))
        preF = 2 * epsilon * rho0 / r0
        for i1, p1 in enumerate(positions):
            for i2, p2 in enumerate(positions[:i1]):
                diff = p2 - p1
                r = sqrt(np.dot(diff, diff))
                expf = exp(rho0 * (1.0 - r / r0))
                energy += epsilon * expf * (expf - 2)
                F = preF * expf * (expf - 1) * diff / r
                forces[i1] -= F
                forces[i2] += F
github rosswhitfield / ase / ase / calculators / combine_mm.py View on Github external
def calculate(self, atoms, properties, system_changes):
        Calculator.calculate(self, atoms, properties, system_changes)

        if self.atoms1 is None:
            self.initialize(atoms)

        pos1 = atoms.positions[self.mask]
        pos2 = atoms.positions[~self.mask]
        self.atoms1.set_positions(pos1)
        self.atoms2.set_positions(pos2)

        # positions and charges for the coupling term, which should
        # include virtual charges and sites:
        spm1 = self.atoms1.calc.sites_per_mol
        spm2 = self.atoms2.calc.sites_per_mol
        xpos1 = self.atoms1.calc.add_virtual_sites(pos1)
        xpos2 = self.atoms2.calc.add_virtual_sites(pos2)