Esempio n. 1
0
    def test_calculator(self):

        from ase.calculators.test import TestPotential
        from ase.calculators.lj import LennardJones

        # Generate a few random structures
        elrnd = ['H', 'C', 'O', 'N']
        asernd = []
        for n in range(4):
            aselen = np.random.randint(2, 10)
            asernd.append(
                Atoms(symbols=np.random.choice(elrnd, aselen),
                      positions=np.random.random((aselen, 3))))

        testcoll = AtomsCollection(asernd)

        testcoll.set_calculators(LennardJones,
                                 labels=['a', 'b', 'c', 'd'],
                                 params={'epsilon': 1.2})
        testcoll.run_calculators()

        def extract_nrg(s):
            return s.calc.results['energy']

        energies = np.array(testcoll.all.map(extract_nrg))

        self.assertTrue(not np.isnan(energies).any())
Esempio n. 2
0
    @staticmethod
    def extract(s):  # This is where the core of the calculation happens
        # s is a single Atoms object passed to this method

        chemsyms = s.get_chemical_symbols()
        h_inds = [i for i, sym in enumerate(chemsyms) if sym == 'H']
        h_pos = s.get_positions()[h_inds]
        com = np.average(h_pos, axis=0)

        return com


print "---- Hydrogen COM for all NH3 configurations\n"
print '\n'.join(['{0}'.format(x) for x in HydrogenCOM.get(nh3coll)]), "\n\n"
"""
3 - CALCULATORS

The Atomic Simulation Environment provides bindings to many codes in the form of calculators.
These include ab initio codes like CASTEP and VASP as well as empirical force fields. These calculators can be set
and used in Soprano as well. Here we're going to use the most basic one, the Lennard-Jones force field,
as an example.
"""
from ase.calculators.lj import LennardJones
from soprano.properties.basic import CalcEnergy

nh3coll.set_calculators(
    LennardJones)  # Creates calculators of the given type for all structures

print "---- NH3 Lennard-Jones energy for all configurations ----\n"
print '\n'.join(['{0}'.format(x) for x in CalcEnergy.get(nh3coll)]), "\n\n"