venuspython 1.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- venuspy/__init__.py +1 -0
- venuspy/calc/bagelcalc.py +198 -0
- venuspy/calc/chempotpycalc.py +108 -0
- venuspy/calc/minisgdmlcalc.py +84 -0
- venuspy/calc/mopaccalc.py +154 -0
- venuspy/calc/nwchemcalc.py +314 -0
- venuspy/calc/nwchemexcalc.py +431 -0
- venuspy/calc/original_nwchemexcalc.py +282 -0
- venuspy/calc/physnetcalc.py +289 -0
- venuspy/calc/psi4calc.py +227 -0
- venuspy/calc/qcengineGAMESScalc.py +213 -0
- venuspy/calc/xtbcalc.py +358 -0
- venuspy/cli.py +584 -0
- venuspy/initialSampling.py +1435 -0
- venuspy/md.py +492 -0
- venuspython-1.0.5.dist-info/METADATA +442 -0
- venuspython-1.0.5.dist-info/RECORD +20 -0
- venuspython-1.0.5.dist-info/WHEEL +5 -0
- venuspython-1.0.5.dist-info/entry_points.txt +2 -0
- venuspython-1.0.5.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from ase.calculators.calculator import Calculator
|
|
4
|
+
from ase.units import Ha, Ang, Bohr
|
|
5
|
+
|
|
6
|
+
# For NWChemEx:
|
|
7
|
+
import simde
|
|
8
|
+
import pluginplay
|
|
9
|
+
from nwchemex import compute_energy, load_modules
|
|
10
|
+
from chemist import Atom, Molecule, ChemicalSystem, PointSetD
|
|
11
|
+
from chemist.basis_set import AtomicBasisSetD
|
|
12
|
+
|
|
13
|
+
from friendzone.nwx2qcengine.call_qcengine import call_qcengine
|
|
14
|
+
|
|
15
|
+
class nwchemexcalculator(Calculator):
|
|
16
|
+
|
|
17
|
+
implemented_properties = ['energy', 'forces']
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
input_path,
|
|
22
|
+
n_threads=1,
|
|
23
|
+
E_to_eV=Ha,
|
|
24
|
+
F_to_eV_Ang=Ha/Bohr,
|
|
25
|
+
use_torch=False,
|
|
26
|
+
*args,
|
|
27
|
+
**kwargs
|
|
28
|
+
):
|
|
29
|
+
"""
|
|
30
|
+
ASE calculator for the NWChemEx ab initio module
|
|
31
|
+
|
|
32
|
+
A calculator takes atomic numbers and atomic positions from an Atoms object and calculates the energy and forces.
|
|
33
|
+
|
|
34
|
+
Note
|
|
35
|
+
----
|
|
36
|
+
ASE uses eV and Angstrom as energy and length unit, respectively. Unless the paramerters `E_to_eV` and `F_to_eV_Ang` are specified, the sGDML model is assumed to use kcal/mol and Angstorm and the appropriate conversion factors are set accordingly.
|
|
37
|
+
Here is how to find them: `ASE units <https://wiki.fysik.dtu.dk/ase/ase/units.html>`_.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
input_path : :obj:`str`
|
|
42
|
+
Path to a NWChemEx input file
|
|
43
|
+
E_to_eV : float, optional
|
|
44
|
+
Conversion factor from whatever energy unit is used by the model to eV. By default this parameter is set to convert from kcal/mol.
|
|
45
|
+
F_to_eV_Ang : float, optional
|
|
46
|
+
Conversion factor from whatever length unit is used by the model to Angstrom. By default, the length unit is not converted (assumed to be in Angstrom)
|
|
47
|
+
use_torch : boolean, optional
|
|
48
|
+
Use PyTorch to calculate predictions
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
super(nwchemexcalculator, self).__init__(*args, **kwargs)
|
|
52
|
+
|
|
53
|
+
# Default values for the input
|
|
54
|
+
self.maxiter = 10000
|
|
55
|
+
self.d_convergence = 1.0e-8
|
|
56
|
+
self.e_convergence = 1.0e-8
|
|
57
|
+
self.referencemethod = 'uhf'
|
|
58
|
+
self.freeze_core = 0
|
|
59
|
+
self.df_ints_io = "None"
|
|
60
|
+
self.method = 'b3lyp' # LevelOfTheory
|
|
61
|
+
self.basis_set = '6-31g*' # BasisSet
|
|
62
|
+
self.mulliken = 0
|
|
63
|
+
self.charge = 0
|
|
64
|
+
self.multiplicity = 2 # 2s+1
|
|
65
|
+
|
|
66
|
+
self.memory = 1500 # In MB
|
|
67
|
+
self.scratchdir = "/tmp"
|
|
68
|
+
|
|
69
|
+
# Read in the input
|
|
70
|
+
with open(input_path, 'r') as f:
|
|
71
|
+
for line in f:
|
|
72
|
+
strippedline=" ".join(line.split())
|
|
73
|
+
entries = strippedline.split(" ")
|
|
74
|
+
if (entries[0] == "memory"): self.memory = int(entries[1])
|
|
75
|
+
if (entries[0] == "scratchdir"): self.scratchdir = str(entries[1])
|
|
76
|
+
if (entries[0] == "referencemethod"): self.referencemethod = str(entries[1])
|
|
77
|
+
if (entries[0] == "freeze_core"): self.freeze_core = int(entries[1])
|
|
78
|
+
if (entries[0] == "df_ints_io"): self.df_ints_io = str(entries[1])
|
|
79
|
+
if (entries[0] == "method"): self.method = str(entries[1])
|
|
80
|
+
if (entries[0] == "basis_set"): self.basis_set = str(entries[1])
|
|
81
|
+
if (entries[0] == "mulliken"): self.mulliken = int(entries[1])
|
|
82
|
+
if (entries[0] == "charge"): self.charge = int(entries[1])
|
|
83
|
+
if (entries[0] == "multiplicity"): self.multiplicity = int(entries[1])
|
|
84
|
+
|
|
85
|
+
self.movecs = self.scratchdir +"/"+".nwchem.tmp.scf.movecs"
|
|
86
|
+
self.movecsSCF = self.movecs
|
|
87
|
+
self.movecsDFT = self.movecs
|
|
88
|
+
self.ref_wfn = None
|
|
89
|
+
|
|
90
|
+
assert (self.method == "SCF") # Only use "NWchem : SCF" for now
|
|
91
|
+
|
|
92
|
+
# Prepare a minimally descriptive "model" for NWChemEx
|
|
93
|
+
self.model = {"method":self.method, "basis":self.basis_set}
|
|
94
|
+
|
|
95
|
+
# Prepare the environment and keywords for NWChemEx/QCEngine
|
|
96
|
+
self.method = "NWChem : " + self.method
|
|
97
|
+
self.keywords = {
|
|
98
|
+
# "geometry__nocenter": ".true.", # Required
|
|
99
|
+
# "geometry__noautoz" : ".true.", # (Basically) required
|
|
100
|
+
"scf; "+self.referencemethod+"; " : "end", # The reference wavefunction
|
|
101
|
+
"set scf:maxiter" : self.maxiter, # Max number of iterations for the main wavefunction SCF
|
|
102
|
+
"set cphf:maxiter" : self.maxiter, # Max number of iterations for the reference wavefunction
|
|
103
|
+
"set scf:thresh" : self.e_convergence, # Energy convergence threshold
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
mpiexec_command = "srun --overlap --mpi=pmix --nodes={nnodes} --ntasks-per-node={ranks_per_node} --ntasks={total_ranks} --cpus-per-task={cores_per_rank}" # For QCEngine, it has to be of this format: (1) nodes, (2) ranks_per_node, (3) total_ranks, (4) cores_per_rank
|
|
107
|
+
self.MPIconfig = {
|
|
108
|
+
"use_mpiexec" : True,
|
|
109
|
+
"mpiexec_command": mpiexec_command,
|
|
110
|
+
"nnodes": 1,
|
|
111
|
+
"ncores": n_threads,
|
|
112
|
+
"cores_per_rank": 2,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
self.mm = pluginplay.ModuleManager()
|
|
116
|
+
load_modules(self.mm)
|
|
117
|
+
self.mm.change_input(self.method, 'basis set', self.basis_set)
|
|
118
|
+
self.mm.change_input(self.method + " Gradient", 'basis set', self.basis_set)
|
|
119
|
+
self.mm.change_input(self.method, 'MPI config', self.MPIconfig)
|
|
120
|
+
self.mm.change_input(self.method + " Gradient", 'MPI config', self.MPIconfig)
|
|
121
|
+
# self.mm.change_input(self.method, 'keywords', self.keywords)
|
|
122
|
+
# self.mm.change_input(self.method + " Gradient", 'keywords', self.keywords)
|
|
123
|
+
|
|
124
|
+
# Set the number of threads used in this session
|
|
125
|
+
self.n_tasks = n_threads
|
|
126
|
+
|
|
127
|
+
# Converts energy from the unit used by the ab initio method to eV.
|
|
128
|
+
self.E_to_eV = E_to_eV
|
|
129
|
+
|
|
130
|
+
# Converts length from the unit used in the ab initio method to Ang.
|
|
131
|
+
self.Ang_to_R = F_to_eV_Ang / E_to_eV
|
|
132
|
+
|
|
133
|
+
# Converts force from the unit used by the ab initio method to eV/Ang.
|
|
134
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
135
|
+
|
|
136
|
+
print("Summary of NWChemEx ab initio input file (for NWChem)")
|
|
137
|
+
print(" Model:", self.model)
|
|
138
|
+
print(" Keywords:", self.keywords)
|
|
139
|
+
print(" nproc:", self.n_tasks)
|
|
140
|
+
|
|
141
|
+
def calculate(self, atoms=None, *args, **kwargs):
|
|
142
|
+
|
|
143
|
+
super(nwchemexcalculator, self).calculate(atoms, *args, **kwargs)
|
|
144
|
+
|
|
145
|
+
# Convert model units to ASE default units
|
|
146
|
+
r = np.array(atoms.get_positions()) * self.Ang_to_R
|
|
147
|
+
|
|
148
|
+
# # Load the geometry into the Chemist objects
|
|
149
|
+
chemist_mol = Molecule()
|
|
150
|
+
for anAtom in atoms:
|
|
151
|
+
chemist_mol.push_back(Atom(anAtom.symbol,anAtom.number,anAtom.mass,*anAtom.position * self.Ang_to_R))
|
|
152
|
+
chemist_mol.set_charge(self.charge)
|
|
153
|
+
chemist_mol.set_multiplicity(self.multiplicity)
|
|
154
|
+
chemist_sys = ChemicalSystem(chemist_mol)
|
|
155
|
+
|
|
156
|
+
# Try the SCF convergence a few times with different approaches:
|
|
157
|
+
# (1) Try using the reference wavefunction (from the previous step)
|
|
158
|
+
# (2) Try the default superposition of atomic densities (SAD)
|
|
159
|
+
# tmp_d_convergence = self.d_convergence
|
|
160
|
+
# tmp_e_convergence = self.e_convergence
|
|
161
|
+
# for i in range(100):
|
|
162
|
+
# if (self.ref_wfn is None):
|
|
163
|
+
# try:
|
|
164
|
+
# e, self.ref_wfn = psi4.energy(self.psi4method,write_orbitals=self.movecs,return_wfn=True)
|
|
165
|
+
# psi4.set_options({'d_convergence': self.d_convergence})
|
|
166
|
+
# psi4.set_options({'e_convergence': self.e_convergence})
|
|
167
|
+
# break
|
|
168
|
+
# except SCFConvergenceError:
|
|
169
|
+
# if (i==10):
|
|
170
|
+
# raise SCFConvergenceError("SCF convergence failed too many times in a row!")
|
|
171
|
+
# print("SCF convergence ({0}) ... will now increase convergence threshold by a factor of 3".format(i))
|
|
172
|
+
# tmp_d_convergence = tmp_d_convergence * 3
|
|
173
|
+
# tmp_e_convergence = tmp_e_convergence * 3
|
|
174
|
+
# psi4.set_options({'d_convergence': tmp_d_convergence})
|
|
175
|
+
# psi4.set_options({'e_convergence': tmp_e_convergence})
|
|
176
|
+
# else:
|
|
177
|
+
# try:
|
|
178
|
+
# e, self.ref_wfn = psi4.energy(self.psi4method,restart_file=self.movecs,write_orbitals=self.movecs,return_wfn=True)
|
|
179
|
+
# break
|
|
180
|
+
# except SCFConvergenceError:
|
|
181
|
+
# print("SCF convergence (0) ... will now use a SAD guess")
|
|
182
|
+
# self.ref_wfn = None
|
|
183
|
+
|
|
184
|
+
if True: # Using "run_as"
|
|
185
|
+
if (self.ref_wfn is None):
|
|
186
|
+
self.keywords["scf; vectors "] = " output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
187
|
+
self.keywords["dft; vectors "] = " output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
188
|
+
|
|
189
|
+
else:
|
|
190
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
191
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
192
|
+
|
|
193
|
+
print(self.mm)
|
|
194
|
+
print(self.method, self.basis_set, chemist_sys)
|
|
195
|
+
print(self.model)
|
|
196
|
+
print(self.keywords)
|
|
197
|
+
|
|
198
|
+
self.mm.change_input(self.method, 'keywords', self.keywords)
|
|
199
|
+
e = self.mm.run_as(simde.TotalEnergy(), self.method, chemist_sys)
|
|
200
|
+
self.ref_wfn = True
|
|
201
|
+
|
|
202
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
203
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
204
|
+
self.mm.change_input(self.method + " Gradient", 'keywords', self.keywords)
|
|
205
|
+
|
|
206
|
+
# f = self.mm.run_as(simde.provisional.EnergyNuclearGradientD(), self.method + " Gradient", chemist_sys)
|
|
207
|
+
f = self.mm.run_as(simde.EnergyNuclearGradientStdVectorD(), self.method + " Gradient", chemist_sys, PointSetD())
|
|
208
|
+
# f = -np.array(f).reshape(-1,3)
|
|
209
|
+
f = np.array(f).reshape(-1,3)
|
|
210
|
+
|
|
211
|
+
if False:
|
|
212
|
+
print(self.mm)
|
|
213
|
+
print(self.method, self.basis_set, chemist_sys)
|
|
214
|
+
print(self.model)
|
|
215
|
+
print(self.keywords)
|
|
216
|
+
print(" simde.TotalEnergy(): ", simde.TotalEnergy())
|
|
217
|
+
print("inputs of simde.TotalEnergy(): ", simde.TotalEnergy().inputs)
|
|
218
|
+
print("Now PREPARING (inputs) of the dummy module:")
|
|
219
|
+
self.mm.change_input('InitQP : samplingMethod1', 'basis set', self.basis_set)
|
|
220
|
+
# self.mm.change_submod('InitQP : samplingMethod1', 'energy submodule', simde.TotalEnergy())
|
|
221
|
+
self.mm.change_submod('InitQP : samplingMethod1', 'energy submodule', 'NWChem : SCF')
|
|
222
|
+
self.mm.change_submod('InitQP : samplingMethod1', 'gradient submodule', 'NWChem : SCF Gradient')
|
|
223
|
+
print("Now STARTING the dummy module:")
|
|
224
|
+
# qp = self.mm.run_as("", 'InitQP : samplingMethod1', chemist_sys)
|
|
225
|
+
qp = self.mm.run_as(simde.TotalEnergy(), 'InitQP : samplingMethod1', chemist_sys)
|
|
226
|
+
print("Now FINISHING the dummy module:")
|
|
227
|
+
print("QP: ", qp)
|
|
228
|
+
|
|
229
|
+
else: # Skipping "run_as"
|
|
230
|
+
if (self.ref_wfn is None):
|
|
231
|
+
self.keywords["scf; vectors "] = " output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
232
|
+
self.keywords["dft; vectors "] = " output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
233
|
+
|
|
234
|
+
e = call_qcengine(simde.TotalEnergy(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
235
|
+
self.ref_wfn = True
|
|
236
|
+
|
|
237
|
+
else:
|
|
238
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
239
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
240
|
+
|
|
241
|
+
e = call_qcengine(simde.TotalEnergy(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
242
|
+
|
|
243
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
244
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
245
|
+
|
|
246
|
+
f = call_qcengine(simde.provisional.EnergyNuclearGradientD(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
247
|
+
# f = -np.array(f)
|
|
248
|
+
f = np.array(f)
|
|
249
|
+
|
|
250
|
+
# Make sure that the gradient was correctly read in
|
|
251
|
+
assert len(atoms) == len(f)
|
|
252
|
+
|
|
253
|
+
# If there are 'extra' things, do them here (e.g., Mulliken analysis)
|
|
254
|
+
# if (self.mulliken > 0):
|
|
255
|
+
# self.oeprop = OEProp(self.ref_wfn)
|
|
256
|
+
# self.oeprop.add("MULLIKEN_CHARGES")
|
|
257
|
+
# self.oeprop.compute()
|
|
258
|
+
|
|
259
|
+
# Convert model units to ASE default units (eV and Ang)
|
|
260
|
+
e *= self.E_to_eV
|
|
261
|
+
f *= -self.F_to_eV_Ang
|
|
262
|
+
|
|
263
|
+
print("f:", f)
|
|
264
|
+
|
|
265
|
+
f = f.reshape(-1, 3)
|
|
266
|
+
Natoms = len(atoms)
|
|
267
|
+
print("")
|
|
268
|
+
print("NWChemEx flag 1")
|
|
269
|
+
print(Natoms)
|
|
270
|
+
print("Energy: ", e)
|
|
271
|
+
#for anAtom in atoms:
|
|
272
|
+
for i in range(Natoms):
|
|
273
|
+
anAtom = atoms[i]
|
|
274
|
+
print("{0:2s} {1:16.8f} {2:16.8f} {3:16.8f} {4:18.10f} {5:18.10f} {6:18.10f}".format(anAtom.symbol,*anAtom.position, *f[i]))
|
|
275
|
+
print("")
|
|
276
|
+
|
|
277
|
+
self.results = {'energy': e, 'forces': f}
|
|
278
|
+
|
|
279
|
+
def get_forces(self, atoms=None, force_consistent=False):
|
|
280
|
+
forces = self.get_property('forces', atoms)
|
|
281
|
+
return forces
|
|
282
|
+
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
#import tensorflow as tf
|
|
4
|
+
import tensorflow.compat.v1 as tf
|
|
5
|
+
#tf.compat.v1.disable_eager_execution()
|
|
6
|
+
#tf.disable_eager_execution() # Kazuumi change for the Physnet (tensorflow 1.14.0) + Psi4 install
|
|
7
|
+
#tf.disable_v2_behavior()
|
|
8
|
+
|
|
9
|
+
from PhysNet.neural_network.NeuralNetwork import NeuralNetwork as PN_NeuralNetwork
|
|
10
|
+
from PhysNet.neural_network.activation_fn import shifted_softplus as PN_shifted_softplus
|
|
11
|
+
import tensorflow.compat.v1 as tf
|
|
12
|
+
import numpy as np
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import argparse
|
|
16
|
+
import logging
|
|
17
|
+
import string
|
|
18
|
+
import random
|
|
19
|
+
from shutil import copyfile
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
|
|
22
|
+
# Kazuumi additions:
|
|
23
|
+
import ase
|
|
24
|
+
from ase.neighborlist import neighbor_list
|
|
25
|
+
from ase import units
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def softplus_inverse(x):
|
|
29
|
+
'''numerically stable inverse of softplus transform'''
|
|
30
|
+
return x + np.log(-np.expm1(-x))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
'''
|
|
34
|
+
Calculator for the atomic simulation environment (ASE)
|
|
35
|
+
that evaluates energies and forces using a neural network
|
|
36
|
+
'''
|
|
37
|
+
class PNCalculator:
|
|
38
|
+
#most parameters are just passed to the neural network
|
|
39
|
+
def __init__(self,
|
|
40
|
+
config_file, #ckpt file from which to restore the model (can also be a list for ensembles)
|
|
41
|
+
atoms, #ASE atoms object
|
|
42
|
+
E_to_eV=units.kcal/units.mol,
|
|
43
|
+
F_to_eV_Ang=units.kcal/units.mol,
|
|
44
|
+
charge=0, #system charge
|
|
45
|
+
dtype=tf.float32): #single or double precision
|
|
46
|
+
|
|
47
|
+
#define command line arguments
|
|
48
|
+
PNparser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
|
49
|
+
PNparser.add_argument("--restart", type=str, default=None, help="restart training from a specific folder")
|
|
50
|
+
PNparser.add_argument("--num_features", type=int, help="dimensionality of feature vectors")
|
|
51
|
+
PNparser.add_argument("--num_basis", type=int, help="number of radial basis functions")
|
|
52
|
+
PNparser.add_argument("--num_blocks", type=int, help="number of interaction blocks")
|
|
53
|
+
PNparser.add_argument("--num_residual_atomic", type=int, help="number of residual layers for atomic refinements")
|
|
54
|
+
PNparser.add_argument("--num_residual_interaction", type=int, help="number of residual layers for the message phase")
|
|
55
|
+
PNparser.add_argument("--num_residual_output", type=int, help="number of residual layers for the output blocks")
|
|
56
|
+
PNparser.add_argument("--cutoff", default=10.0, type=float, help="cutoff distance for short range interactions")
|
|
57
|
+
PNparser.add_argument("--use_electrostatic", default=1, type=int, help="use electrostatics in energy prediction (0/1)")
|
|
58
|
+
PNparser.add_argument("--use_dispersion", default=1, type=int, help="use dispersion in energy prediction (0/1)")
|
|
59
|
+
PNparser.add_argument("--grimme_s6", default=None, type=float, help="grimme s6 dispersion coefficient")
|
|
60
|
+
PNparser.add_argument("--grimme_s8", default=None, type=float, help="grimme s8 dispersion coefficient")
|
|
61
|
+
PNparser.add_argument("--grimme_a1", default=None, type=float, help="grimme a1 dispersion coefficient")
|
|
62
|
+
PNparser.add_argument("--grimme_a2", default=None, type=float, help="grimme a2 dispersion coefficient")
|
|
63
|
+
args = PNparser.parse_args(["@"+config_file])
|
|
64
|
+
|
|
65
|
+
# checkpoint=args.restart # In the original, we would load the directory
|
|
66
|
+
# checkpointfile = tf.train.latest_checkpoint(checkpoint) #
|
|
67
|
+
# print("I see the checkpoint: ", checkpoint)
|
|
68
|
+
# print("I see the checkpoint file: ", checkpointfile)
|
|
69
|
+
checkpointfile=args.restart # but here we just load the file itself
|
|
70
|
+
|
|
71
|
+
# If we may have multiple sessions / models, we may need to reset the graph at the start
|
|
72
|
+
tf.reset_default_graph()
|
|
73
|
+
|
|
74
|
+
#create neural network
|
|
75
|
+
# self._nn = NeuralNetwork(F=args.num_features,
|
|
76
|
+
self._nn = PN_NeuralNetwork(F=args.num_features,
|
|
77
|
+
K=args.num_basis,
|
|
78
|
+
sr_cut=args.cutoff,
|
|
79
|
+
num_blocks=args.num_blocks,
|
|
80
|
+
num_residual_atomic=args.num_residual_atomic,
|
|
81
|
+
num_residual_interaction=args.num_residual_interaction,
|
|
82
|
+
num_residual_output=args.num_residual_output,
|
|
83
|
+
use_electrostatic=(args.use_electrostatic==1),
|
|
84
|
+
use_dispersion=(args.use_dispersion==1),
|
|
85
|
+
s6=args.grimme_s6,
|
|
86
|
+
s8=args.grimme_s8,
|
|
87
|
+
a1=args.grimme_a1,
|
|
88
|
+
a2=args.grimme_a2,
|
|
89
|
+
activation_fn=PN_shifted_softplus,
|
|
90
|
+
# activation_fn=shifted_softplus,
|
|
91
|
+
scope="neural_network")
|
|
92
|
+
|
|
93
|
+
self._sess = tf.Session()
|
|
94
|
+
if checkpointfile is not None:
|
|
95
|
+
self._nn._saver.restore(self._sess, checkpointfile)
|
|
96
|
+
else:
|
|
97
|
+
raise ValueError("I guess you're not as smart as you thought you were buddy.")
|
|
98
|
+
|
|
99
|
+
# Converts energies and forces
|
|
100
|
+
self.E_to_eV = E_to_eV
|
|
101
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
102
|
+
|
|
103
|
+
#create neighborlist
|
|
104
|
+
if True:
|
|
105
|
+
self._sr_cutoff = self._nn.sr_cut
|
|
106
|
+
self._lr_cutoff = None
|
|
107
|
+
self._use_neighborlist = False
|
|
108
|
+
if False:
|
|
109
|
+
self._sr_cutoff = self._nn.sr_cut
|
|
110
|
+
self._lr_cutoff = self._nn.sr_cut * 2
|
|
111
|
+
self._use_neighborlist = True
|
|
112
|
+
|
|
113
|
+
#create placeholders for feeding data
|
|
114
|
+
self._Q_tot = np.array(1*[charge])
|
|
115
|
+
self._Z = tf.placeholder(tf.int32, shape=[None, ], name="Z")
|
|
116
|
+
self._R = tf.placeholder(dtype, shape=[None,3], name="R")
|
|
117
|
+
self._idx_i = tf.placeholder(tf.int32, shape=[None, ], name="idx_i")
|
|
118
|
+
self._idx_j = tf.placeholder(tf.int32, shape=[None, ], name="idx_j")
|
|
119
|
+
self._offsets = tf.placeholder(dtype, shape=[None,3], name="offsets")
|
|
120
|
+
self._sr_idx_i = tf.placeholder(tf.int32, shape=[None, ], name="sr_idx_i")
|
|
121
|
+
self._sr_idx_j = tf.placeholder(tf.int32, shape=[None, ], name="sr_idx_j")
|
|
122
|
+
self._sr_offsets = tf.placeholder(dtype, shape=[None,3], name="sr_offsets")
|
|
123
|
+
|
|
124
|
+
#calculate atomic charges, energy and force evaluation nodes
|
|
125
|
+
if self.use_neighborlist:
|
|
126
|
+
Ea, Qa, Dij, nhloss = self.nn.atomic_properties(self.Z, self.R, self.idx_i, self.idx_j, self.offsets, self.sr_idx_i, self.sr_idx_j, self.sr_offsets)
|
|
127
|
+
else:
|
|
128
|
+
Ea, Qa, Dij, nhloss = self.nn.atomic_properties(self.Z, self.R, self.idx_i, self.idx_j, self.offsets)
|
|
129
|
+
self._charges = self.nn.scaled_charges(self.Z, Qa, self.Q_tot)
|
|
130
|
+
self._energy, self._forces = self.nn.energy_and_forces_from_scaled_atomic_properties(Ea, self.charges, Dij, self.Z, self.R, self.idx_i, self.idx_j)
|
|
131
|
+
|
|
132
|
+
# #calculate atomic charges, energy and force evaluation nodes
|
|
133
|
+
# if self.use_neighborlist:
|
|
134
|
+
# Ea, Qa, Dij, nhloss = nn.atomic_properties(self.Z, self.R, self.idx_i, self.idx_j, self.offsets, self.sr_idx_i, self.sr_idx_j, self.sr_offsets)
|
|
135
|
+
# else:
|
|
136
|
+
# Ea, Qa, Dij, nhloss = nn.atomic_properties(self.Z, self.R, self.idx_i, self.idx_j, self.offsets)
|
|
137
|
+
# self._charges =nn.scaled_charges(self.Z, Qa, self.Q_tot)
|
|
138
|
+
# self._energy, self._forces = nn.energy_and_forces_from_scaled_atomic_properties(Ea, self.charges, Dij, self.Z, self.R, self.idx_i, self.idx_j)
|
|
139
|
+
|
|
140
|
+
#calculate properties once to initialize everything
|
|
141
|
+
self._calculate_all_properties(atoms)
|
|
142
|
+
|
|
143
|
+
def calculation_required(self, atoms, quantities=None):
|
|
144
|
+
return atoms != self.last_atoms
|
|
145
|
+
|
|
146
|
+
def _calculate_all_properties(self, atoms):
|
|
147
|
+
#find neighbors and offsets
|
|
148
|
+
if self.use_neighborlist or any(atoms.get_pbc()):
|
|
149
|
+
idx_i, idx_j, S = neighbor_list('ijS', atoms, self.lr_cutoff)
|
|
150
|
+
offsets = np.dot(S, atoms.get_cell())
|
|
151
|
+
sr_idx_i, sr_idx_j, sr_S = neighbor_list('ijS', atoms, self.sr_cutoff)
|
|
152
|
+
sr_offsets = np.dot(sr_S, atoms.get_cell())
|
|
153
|
+
feed_dict = {self.Z: atoms.get_atomic_numbers(), self.R: atoms.get_positions(),
|
|
154
|
+
self.idx_i: idx_i, self.idx_j: idx_j, self.offsets: offsets,
|
|
155
|
+
self.sr_idx_i: sr_idx_i, self.sr_idx_j: sr_idx_j, self.sr_offsets: sr_offsets}
|
|
156
|
+
else:
|
|
157
|
+
N = len(atoms)
|
|
158
|
+
idx_i = np.zeros([N*(N-1)], dtype=int)
|
|
159
|
+
|
|
160
|
+
idx_j = np.zeros([N*(N-1)], dtype=int)
|
|
161
|
+
offsets = np.zeros([N*(N-1),3], dtype=float)
|
|
162
|
+
count = 0
|
|
163
|
+
for i in range(N):
|
|
164
|
+
for j in range(N):
|
|
165
|
+
if i != j:
|
|
166
|
+
idx_i[count] = i
|
|
167
|
+
idx_j[count] = j
|
|
168
|
+
count += 1
|
|
169
|
+
feed_dict = {self.Z: atoms.get_atomic_numbers(), self.R: atoms.get_positions(),
|
|
170
|
+
self.idx_i: idx_i, self.idx_j: idx_j, self.offsets: offsets}
|
|
171
|
+
|
|
172
|
+
#calculate energy and forces (in case multiple NNs are used as ensemble, this forms the average)
|
|
173
|
+
self._last_energy, self._last_forces, self._last_charges = self.sess.run([self.energy, self.forces, self.charges], feed_dict=feed_dict)
|
|
174
|
+
self._energy_stdev = 0
|
|
175
|
+
|
|
176
|
+
# Kazuumi's addition
|
|
177
|
+
self._last_energy = self._last_energy * self.E_to_eV
|
|
178
|
+
self._last_forces = self._last_forces * self.F_to_eV_Ang
|
|
179
|
+
|
|
180
|
+
self._last_energy = np.array(1*[self.last_energy]) #prevents some problems...
|
|
181
|
+
|
|
182
|
+
#store copy of atoms
|
|
183
|
+
self._last_atoms = atoms.copy()
|
|
184
|
+
|
|
185
|
+
def get_potential_energy(self, atoms, force_consistent=False):
|
|
186
|
+
if self.calculation_required(atoms):
|
|
187
|
+
self._calculate_all_properties(atoms)
|
|
188
|
+
return self.last_energy
|
|
189
|
+
|
|
190
|
+
def get_forces(self, atoms):
|
|
191
|
+
if self.calculation_required(atoms):
|
|
192
|
+
self._calculate_all_properties(atoms)
|
|
193
|
+
return self.last_forces
|
|
194
|
+
|
|
195
|
+
def get_charges(self, atoms):
|
|
196
|
+
if self.calculation_required(atoms):
|
|
197
|
+
self._calculate_all_properties(atoms)
|
|
198
|
+
return self.last_charges
|
|
199
|
+
|
|
200
|
+
###################################################################################################################
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def sess(self):
|
|
204
|
+
return self._sess
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def last_atoms(self):
|
|
208
|
+
return self._last_atoms
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def last_energy(self):
|
|
212
|
+
return self._last_energy
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def last_forces(self):
|
|
216
|
+
return self._last_forces
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def last_charges(self):
|
|
220
|
+
return self._last_charges
|
|
221
|
+
|
|
222
|
+
@property
|
|
223
|
+
def energy_stdev(self):
|
|
224
|
+
return self._energy_stdev
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def sr_cutoff(self):
|
|
228
|
+
return self._sr_cutoff
|
|
229
|
+
|
|
230
|
+
@property
|
|
231
|
+
def lr_cutoff(self):
|
|
232
|
+
return self._lr_cutoff
|
|
233
|
+
|
|
234
|
+
@property
|
|
235
|
+
def use_neighborlist(self):
|
|
236
|
+
return self._use_neighborlist
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def nn(self):
|
|
240
|
+
return self._nn
|
|
241
|
+
|
|
242
|
+
@property
|
|
243
|
+
def Z(self):
|
|
244
|
+
return self._Z
|
|
245
|
+
|
|
246
|
+
@property
|
|
247
|
+
def Q_tot(self):
|
|
248
|
+
return self._Q_tot
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def R(self):
|
|
252
|
+
return self._R
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def offsets(self):
|
|
256
|
+
return self._offsets
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def idx_i(self):
|
|
260
|
+
return self._idx_i
|
|
261
|
+
|
|
262
|
+
@property
|
|
263
|
+
def idx_j(self):
|
|
264
|
+
return self._idx_j
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def sr_offsets(self):
|
|
268
|
+
return self._sr_offsets
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def sr_idx_i(self):
|
|
272
|
+
return self._sr_idx_i
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def sr_idx_j(self):
|
|
276
|
+
return self._sr_idx_j
|
|
277
|
+
|
|
278
|
+
@property
|
|
279
|
+
def energy(self):
|
|
280
|
+
return self._energy
|
|
281
|
+
|
|
282
|
+
@property
|
|
283
|
+
def forces(self):
|
|
284
|
+
return self._forces
|
|
285
|
+
|
|
286
|
+
@property
|
|
287
|
+
def charges(self):
|
|
288
|
+
return self._charges
|
|
289
|
+
|