def test_ase(self):
     from ase import Atoms
     from deepmd.calculator import DP
     water0 = Atoms('OHHOHH',
                    positions=self.coords.reshape((-1, 3)),
                    cell=self.box.reshape((3, 3)),
                    calculator=DP(FROZEN_MODEL))
     water1 = Atoms('OHHOHH',
                    positions=self.coords.reshape((-1, 3)),
                    cell=self.box.reshape((3, 3)),
                    calculator=DP(COMPRESSED_MODEL))
     ee0 = water0.get_potential_energy()
     ff0 = water0.get_forces()
     ee1 = water1.get_potential_energy()
     ff1 = water1.get_forces()
     nframes = 1
     np.testing.assert_almost_equal(ff0, ff1, default_places)
     np.testing.assert_almost_equal(ee0, ee1, default_places)
Ejemplo n.º 2
0
 def test_ase(self):
     from ase import Atoms
     from deepmd.calculator import DP
     water = Atoms('OHHOHH',
                   positions=self.coords.reshape((-1, 3)),
                   cell=self.box.reshape((3, 3)),
                   calculator=DP("deeppot.pb"))
     ee = water.get_potential_energy()
     ff = water.get_forces()
     nframes = 1
     np.testing.assert_almost_equal(ff.ravel(), self.expected_f.ravel(),
                                    default_places)
     expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
     np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(),
                                    default_places)
Ejemplo n.º 3
0
import time
from ase import Atoms
from ase.optimize import BFGS
from pprint import pprint
from deepmd.calculator import DP
from pymatgen.io.ase import AseAtomsAdaptor,Structure
from pyxtal.symmetry import get_symbol_and_number
from pymatgen.io.cif import CifWriter
from pymatgen.symmetry.analyzer import PointGroupAnalyzer
from pyxtal.crystal import random_crystal, random_crystal_1D, random_crystal_2D, random_cluster
from pymatgen import Molecule,Structure
import numpy as np
from monty.serialization import loadfn,dumpfn
import random
vac=15
calc=DP(model="frozen_model.pb",type_dict={'Au':0})

def gen_cluster(system,numIons,sg=None,dimension=0,factor=1.0):
    #space group
    random.seed(int(time.time()*1e5))
    if sg:
       pass
    else:
       sg=random.choice(range(1,57))
    symbol, sg = get_symbol_and_number(sg, dimension)

    numIons0 = np.array(numIons)
    cluster = random_cluster(sg, system, numIons0, factor)
    if cluster.valid:
       comp = str(cluster.struct.composition)
       comp = comp.replace(" ", "")
Ejemplo n.º 4
0
import os
from ase import Atoms
from ase.optimize import BFGS
from deepmd.calculator import DP
from pymatgen.io.ase import AseAtomsAdaptor, Structure
from pymatgen import Molecule, Structure
import numpy as np
from monty.serialization import loadfn, dumpfn
import random

st = Structure.from_file("rand_Cu16.vasp")
comp = str(st.composition)
comp = comp.replace(" ", "")
aaa = AseAtomsAdaptor()
atoms = aaa.get_atoms(st)
atoms.set_calculator(DP(model="frozen_model.pb", type_dict={'Cu': 0}))
dyn = BFGS(atoms)
#dyn = BFGS(atoms,trajectory=comp+'.traj')
dyn.run(fmax=1e-4)
aaa.get_structure(atoms)
opted = aaa.get_structure(atoms)
Ejemplo n.º 5
0
        help='if using dp'
    )
    parser.add_argument(
        '-g', '--graph', 
        default='graph.pb', help='deep potential'
    )

    args = parser.parse_args()

    # calculate using dp 
    if args.calc:
        frames = read(args.train, ':')

        from deepmd.calculator import DP 
        calc = DP(
            model = args.graph, 
            #type_dict = {"O": 1, "Zn": 2, "Cr": 0}
        )
        data_dict = {'ener': [[],[]], 'force': [[],[]]}
        for atoms in frames:
            natoms = len(atoms) 
            energy = atoms.get_potential_energy() / natoms
            forces = atoms.get_forces() 
            data_dict['ener'][0].append(energy)
            data_dict['force'][0].extend(forces.flatten().tolist())
            # calculation 
            calc.reset() 
            atoms.calc = calc 
            energy = atoms.get_potential_energy() / natoms
            forces = atoms.get_forces()
            data_dict['ener'][1].append(energy)
            data_dict['force'][1].extend(forces.flatten().tolist())