|
10 | 10 | (1.9575, 1, 1), |
11 | 11 | (1., 1., 1.)], |
12 | 12 | cell=[100, 100, 100], |
13 | | - calculator=DP(model="frozen_model.pb", type_map=['O', 'H'])) |
| 13 | + calculator=DP(model="frozen_model.pb")) |
14 | 14 | print(water.get_potential_energy()) |
15 | 15 | print(water.get_forces()) |
16 | 16 | ``` |
|
25 | 25 | """ |
26 | 26 |
|
27 | 27 | from ase.calculators.calculator import Calculator, all_changes |
28 | | -import deepmd.DeepPot as DPinference |
| 28 | +import deepmd.DeepPot as DeepPot |
29 | 29 |
|
30 | 30 |
|
31 | 31 | class DP(Calculator): |
32 | 32 | name = "DP" |
33 | 33 | implemented_properties = ["energy", "forces", "stress"] |
34 | 34 |
|
35 | | - def __init__(self, model, type_map, label="DP", **kwargs): |
| 35 | + def __init__(self, model, label="DP", **kwargs): |
36 | 36 | Calculator.__init__(self, label=label, **kwargs) |
37 | | - self.dp = DPinference(model) |
38 | | - self.type_map = type_map |
| 37 | + self.dp = DeepPot(model) |
39 | 38 |
|
40 | 39 | def calculate(self, atoms=None, properties=["energy", "forces", "stress"], system_changes=all_changes): |
41 | 40 | coord = atoms.get_positions().reshape([1, -1]) |
42 | 41 | cell = atoms.get_cell().reshape([1, -1]) |
43 | 42 | symbols = atoms.get_chemical_symbols() |
44 | | - type_dict = dict(zip(self.type_map, range(len(self.type_map)))) |
| 43 | + type_dict = dict(zip(self.dp.get_type_map(), range(self.dp.get_ntypes()))) |
45 | 44 | atype = [type_dict[k] for k in symbols] |
46 | 45 | e, f, v = self.dp.eval(coord, cell, atype) |
47 | 46 | self.results['energy'] = e[0] |
|
0 commit comments