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,431 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import shutil, os
|
|
3
|
+
|
|
4
|
+
from ase.calculators.calculator import Calculator
|
|
5
|
+
from ase.units import Ha, Ang, Bohr
|
|
6
|
+
|
|
7
|
+
# For NWChemEx:
|
|
8
|
+
import simde
|
|
9
|
+
import pluginplay
|
|
10
|
+
from nwchemex import compute_energy, load_modules
|
|
11
|
+
from chemist import Atom, Molecule, ChemicalSystem, PointSetD
|
|
12
|
+
from chemist.basis_set import AtomicBasisSetD
|
|
13
|
+
from chemist import PointSetD
|
|
14
|
+
|
|
15
|
+
from friendzone.nwx2qcengine.call_qcengine import call_qcengine
|
|
16
|
+
|
|
17
|
+
class nwchemexcalculator(Calculator):
|
|
18
|
+
|
|
19
|
+
implemented_properties = ['energy', 'forces']
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
input_path,
|
|
24
|
+
output_path=None,
|
|
25
|
+
n_threads=1,
|
|
26
|
+
E_to_eV=Ha,
|
|
27
|
+
F_to_eV_Ang=Ha/Bohr,
|
|
28
|
+
use_torch=False,
|
|
29
|
+
*args,
|
|
30
|
+
**kwargs
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
ASE calculator for the NWChemEx ab initio module
|
|
34
|
+
|
|
35
|
+
A calculator takes atomic numbers and atomic positions from an Atoms object and calculates the energy and forces.
|
|
36
|
+
|
|
37
|
+
Note
|
|
38
|
+
----
|
|
39
|
+
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.
|
|
40
|
+
Here is how to find them: `ASE units <https://wiki.fysik.dtu.dk/ase/ase/units.html>`_.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
input_path : :obj:`str`
|
|
45
|
+
Path to a NWChemEx input file
|
|
46
|
+
E_to_eV : float, optional
|
|
47
|
+
Conversion factor from whatever energy unit is used by the model to eV. By default this parameter is set to convert from kcal/mol.
|
|
48
|
+
F_to_eV_Ang : float, optional
|
|
49
|
+
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)
|
|
50
|
+
use_torch : boolean, optional
|
|
51
|
+
Use PyTorch to calculate predictions
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
super(nwchemexcalculator, self).__init__(*args, **kwargs)
|
|
55
|
+
|
|
56
|
+
# Some suggested default values (for MD)
|
|
57
|
+
# self.maxiter = 5000
|
|
58
|
+
# self.d_convergence = 1.0e-8
|
|
59
|
+
# self.e_convergence = 1.0e-8
|
|
60
|
+
# self.freeze_core = 1
|
|
61
|
+
|
|
62
|
+
# Default values for the input
|
|
63
|
+
self.referencemethod = 'uhf'
|
|
64
|
+
self.method = 'b3lyp' # LevelOfTheory
|
|
65
|
+
self.basis_set = '6-31g*' # BasisSet
|
|
66
|
+
self.charge = 0
|
|
67
|
+
self.multiplicity = 2 # 2s+1
|
|
68
|
+
self.save_movecs_interval = None
|
|
69
|
+
|
|
70
|
+
# Some input values that are currently not set up (handled differently by QCEngine)
|
|
71
|
+
self.memory = 1500 # In MB
|
|
72
|
+
self.scratchdir = "/tmp"
|
|
73
|
+
|
|
74
|
+
self.keywords = {
|
|
75
|
+
# "geometry__nocenter": ".true.", # Required
|
|
76
|
+
# "geometry__noautoz" : ".true.", # (Basically) required
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Read in the input
|
|
80
|
+
with open(input_path, 'r') as f:
|
|
81
|
+
for line in f:
|
|
82
|
+
strippedline=" ".join(line.split())
|
|
83
|
+
entries = strippedline.split(" ")
|
|
84
|
+
# if (entries[0] == "memory"): self.memory = int(entries[1]) # Memory is handled by QCEngine
|
|
85
|
+
# if (entries[0] == "scratchdir"): self.scratchdir = str(entries[1]) # Scratch directories is handled by QCEngine
|
|
86
|
+
if (entries[0] == "referencemethod"):
|
|
87
|
+
self.referencemethod = str(entries[1])
|
|
88
|
+
self.keywords["scf; "+self.referencemethod+"; "] = "end"
|
|
89
|
+
if (self.referencemethod == "rohf" or self.referencemethod == "rodft"):
|
|
90
|
+
self.keywords["dft; cgmin; "] = "end"
|
|
91
|
+
self.keywords["dft; rodft; "] = "end"
|
|
92
|
+
elif (entries[0] == "freeze_core"):
|
|
93
|
+
self.freeze_core = int(entries[1])
|
|
94
|
+
if (self.freeze_core == 1):
|
|
95
|
+
self.keywords["mp2; freeze atomic; "] = "end" # Usually the "core" electrons are assumed to be the ATOMIC core orbitals
|
|
96
|
+
elif (entries[0] == "method"): self.method = str(entries[1])
|
|
97
|
+
elif (entries[0] == "basis_set"):
|
|
98
|
+
# self.basis_set = str(entries[1])
|
|
99
|
+
basis_string_list = entries
|
|
100
|
+
basis_string_list.pop(0)
|
|
101
|
+
self.basis_set = " ".join(basis_string_list)
|
|
102
|
+
# self.basis_set = basis_string_list
|
|
103
|
+
elif (entries[0] == "mulliken"):
|
|
104
|
+
self.mulliken = int(entries[1])
|
|
105
|
+
if (self.mulliken == 1):
|
|
106
|
+
self.keywords["dft; mulliken; "] = "end"
|
|
107
|
+
self.keywords["mp2; mulliken; "] = "end"
|
|
108
|
+
elif (entries[0] == "charge"): self.charge = int(entries[1])
|
|
109
|
+
elif (entries[0] == "multiplicity"): self.multiplicity = int(entries[1])
|
|
110
|
+
elif (entries[0] == "diis"):
|
|
111
|
+
self.diis = int(entries[1])
|
|
112
|
+
if (self.diis == 1):
|
|
113
|
+
self.keywords["scf; diis; "] = "end"
|
|
114
|
+
else:
|
|
115
|
+
self.keywords["dft; nodiis; "] = "end"
|
|
116
|
+
elif (entries[0] == "diisbas"):
|
|
117
|
+
self.diisbas = int(entries[1])
|
|
118
|
+
self.keywords["set scf:diisbas"] = self.diisbas
|
|
119
|
+
# self.keywords["dft; convergence diis nfock "+str(self.diisbas)+"; "] = "end"
|
|
120
|
+
self.keywords["dft; convergence diis "+str(self.diisbas)+"; "] = "end"
|
|
121
|
+
elif (entries[0] == "maxiter"):
|
|
122
|
+
self.maxiter = int(entries[1])
|
|
123
|
+
self.keywords["set scf:maxiter"] = self.maxiter
|
|
124
|
+
self.keywords["set dft:iterations"] = self.maxiter
|
|
125
|
+
elif (entries[0] == "guess_tolerance"): self.keywords["set scf:tolguess"] = float(entries[1])
|
|
126
|
+
elif (entries[0] == "dft_grid"): self.keywords["dft; grid "+str(entries[1])+"; "] = "end"
|
|
127
|
+
elif (entries[0] == "scf_level"):
|
|
128
|
+
level_string_list = entries
|
|
129
|
+
level_string_list.pop(0)
|
|
130
|
+
self.keywords["scf; "+" ".join(level_string_list)+"; "] = "end"
|
|
131
|
+
elif (entries[0] == "dft_convergence_other_options"):
|
|
132
|
+
convergence_string_list = entries
|
|
133
|
+
convergence_string_list.pop(0)
|
|
134
|
+
self.keywords["dft; convergence "+" ".join(convergence_string_list)+"; "] = "end"
|
|
135
|
+
elif (entries[0] == "scf_tol2e"):
|
|
136
|
+
self.keywords["set scf:tol2e"] = float(entries[1])
|
|
137
|
+
elif (entries[0] == "dft_tolerances_tight"):
|
|
138
|
+
if (int(entries[1]) == 1):
|
|
139
|
+
self.keywords["dft; tolerances tight; "] = "end"
|
|
140
|
+
elif (entries[0] == "dft_tolerances_tol_rho"):
|
|
141
|
+
self.keywords["dft; tolerances tol_rho; "+str(entries[1])+"; "] = "end"
|
|
142
|
+
elif (entries[0] == "dft_tolerances_accCoul"):
|
|
143
|
+
self.keywords["dft; tolerances accCoul; "+str(entries[1])+"; "] = "end"
|
|
144
|
+
elif (entries[0] == "dft_tolerances_radius"):
|
|
145
|
+
self.keywords["dft; tolerances radius; "+str(entries[1])+"; "] = "end"
|
|
146
|
+
elif (entries[0] == "dft_e_convergence"):
|
|
147
|
+
self.keywords["dft; convergence energy "+str(entries[1])+"; "] = "end"
|
|
148
|
+
elif (entries[0] == "dft_d_convergence"):
|
|
149
|
+
self.keywords["dft; convergence density "+str(entries[1])+"; "] = "end"
|
|
150
|
+
elif (entries[0] == "dft_g_convergence"):
|
|
151
|
+
self.keywords["dft; convergence gradient "+str(entries[1])+"; "] = "end"
|
|
152
|
+
elif (entries[0] == "scf_convergence"):
|
|
153
|
+
self.keywords["scf; thresh "+str(entries[1])+"; "] = "end"
|
|
154
|
+
|
|
155
|
+
elif (entries[0] == "scf_direct"):
|
|
156
|
+
if (int(entries[1]) == 1): self.keywords["scf; direct; "] = "end"
|
|
157
|
+
elif (entries[0] == "dft_direct"):
|
|
158
|
+
if (int(entries[1]) == 1): self.keywords["dft; direct; "] = "end"
|
|
159
|
+
elif (entries[0] == "mp2_tight_precision"):
|
|
160
|
+
if (int(entries[1]) == 1):
|
|
161
|
+
self.keywords["mp2; tight; "] = "end"
|
|
162
|
+
elif (entries[0] == "dft_disp_vdw"):
|
|
163
|
+
self.keywords["dft; dft disp vdw "+str(entries[1])+"; "] = "end"
|
|
164
|
+
|
|
165
|
+
elif (entries[0] == "save_movecs_interval"):
|
|
166
|
+
self.save_movecs_interval = int(entries[1])
|
|
167
|
+
self.save_movecs_count = -9999999 # Do not do any saving yet
|
|
168
|
+
|
|
169
|
+
else:
|
|
170
|
+
print("Ignoring keyword line (nothing will be added to the NWChem input file) with entries: ", entries)
|
|
171
|
+
|
|
172
|
+
# Some inputs for details on saving intermediate results
|
|
173
|
+
if (output_path):
|
|
174
|
+
self.outputDIR = os.path.abspath(output_path)
|
|
175
|
+
print("In the NWChemEx calculator, looking at this output directory: " + self.outputDIR)
|
|
176
|
+
self.movecsSCF_restart = self.outputDIR+"/"+".nwchem.tmp.scf.movecs.restart"
|
|
177
|
+
self.movecsDFT_restart = self.outputDIR+"/"+".nwchem.tmp.dft.movecs.restart"
|
|
178
|
+
self.movecsSCF_restart_prev = self.outputDIR+"/"+".nwchem.tmp.scf.movecs.restart.prev"
|
|
179
|
+
self.movecsDFT_restart_prev = self.outputDIR+"/"+".nwchem.tmp.dft.movecs.restart.prev"
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
# Recently added ... I think this is necessary for ODFT
|
|
183
|
+
if (self.referencemethod == "uhf" or self.referencemethod == "odft"):
|
|
184
|
+
self.keywords["dft; odft; "] = "end"
|
|
185
|
+
|
|
186
|
+
# The name of the intermediate file that holds the wavefunction
|
|
187
|
+
self.movecs = self.scratchdir +"/"+".nwchem.tmp.scf.movecs"
|
|
188
|
+
self.movecsSCF = self.scratchdir +"/"+".nwchem.tmp.scf.movecs"
|
|
189
|
+
self.movecsDFT = self.scratchdir +"/"+".nwchem.tmp.dft.movecs"
|
|
190
|
+
|
|
191
|
+
# If the user supplied the wavefunction file, use that for the first step
|
|
192
|
+
if (os.path.isfile(self.movecsSCF)):
|
|
193
|
+
print("Reading wavefunction from previous calculation stored in: " + self.movecsSCF + " ... ")
|
|
194
|
+
self.ref_wfn = True
|
|
195
|
+
else:
|
|
196
|
+
self.ref_wfn = None
|
|
197
|
+
|
|
198
|
+
# Prepare a minimally descriptive "model" for NWChemEx
|
|
199
|
+
self.model = {"method":self.method, "basis":self.basis_set}
|
|
200
|
+
|
|
201
|
+
# Prepare the environment and keywords for NWChemEx/QCEngine
|
|
202
|
+
self.method = "NWChem : " + self.method
|
|
203
|
+
|
|
204
|
+
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
|
|
205
|
+
self.MPIconfig = {
|
|
206
|
+
"use_mpiexec" : True,
|
|
207
|
+
"mpiexec_command": mpiexec_command,
|
|
208
|
+
"nnodes": 1,
|
|
209
|
+
"ncores": n_threads,
|
|
210
|
+
"cores_per_rank": 1,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
self.mm = pluginplay.ModuleManager()
|
|
214
|
+
load_modules(self.mm)
|
|
215
|
+
self.mm.change_input(self.method, 'basis set', self.basis_set)
|
|
216
|
+
self.mm.change_input(self.method + " Gradient", 'basis set', self.basis_set)
|
|
217
|
+
self.mm.change_input(self.method + " EnergyAndGradient", 'basis set', self.basis_set)
|
|
218
|
+
self.mm.change_input(self.method, 'MPI config', self.MPIconfig)
|
|
219
|
+
self.mm.change_input(self.method + " Gradient", 'MPI config', self.MPIconfig)
|
|
220
|
+
self.mm.change_input(self.method + " EnergyAndGradient", 'MPI config', self.MPIconfig)
|
|
221
|
+
|
|
222
|
+
# THESE THREE LINES WERE TEMPORARILY ADDED
|
|
223
|
+
self.ref_wfn = True
|
|
224
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
225
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
226
|
+
self.mm.change_input(self.method + " EnergyAndGradient", 'keywords', self.keywords)
|
|
227
|
+
|
|
228
|
+
# Set the number of threads used in this session
|
|
229
|
+
self.n_tasks = n_threads
|
|
230
|
+
|
|
231
|
+
# Converts energy from the unit used by the ab initio method to eV.
|
|
232
|
+
self.E_to_eV = E_to_eV
|
|
233
|
+
|
|
234
|
+
# Converts length from the unit used in the ab initio method to Ang.
|
|
235
|
+
self.Ang_to_R = F_to_eV_Ang / E_to_eV
|
|
236
|
+
|
|
237
|
+
# Converts force from the unit used by the ab initio method to eV/Ang.
|
|
238
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
239
|
+
|
|
240
|
+
print("Summary of NWChemEx ab initio input file (for NWChem)")
|
|
241
|
+
print(" Model:", self.model)
|
|
242
|
+
print(" Keywords:", self.keywords)
|
|
243
|
+
print(" nproc:", self.n_tasks)
|
|
244
|
+
|
|
245
|
+
def calculate(self, atoms=None, *args, **kwargs):
|
|
246
|
+
|
|
247
|
+
super(nwchemexcalculator, self).calculate(atoms, *args, **kwargs)
|
|
248
|
+
|
|
249
|
+
# Convert model units to ASE default units
|
|
250
|
+
r = np.array(atoms.get_positions()) * self.Ang_to_R
|
|
251
|
+
|
|
252
|
+
# # Load the geometry into the Chemist objects
|
|
253
|
+
chemist_mol = Molecule()
|
|
254
|
+
for anAtom in atoms:
|
|
255
|
+
chemist_mol.push_back(Atom(anAtom.symbol,anAtom.number,anAtom.mass,*anAtom.position * self.Ang_to_R))
|
|
256
|
+
chemist_mol.set_charge(self.charge)
|
|
257
|
+
chemist_mol.set_multiplicity(self.multiplicity)
|
|
258
|
+
chemist_sys = ChemicalSystem(chemist_mol)
|
|
259
|
+
|
|
260
|
+
# Try the SCF convergence a few times with different approaches:
|
|
261
|
+
# (1) Try using the reference wavefunction (from the previous step)
|
|
262
|
+
# (2) Try the default superposition of atomic densities (SAD)
|
|
263
|
+
# tmp_d_convergence = self.d_convergence
|
|
264
|
+
# tmp_e_convergence = self.e_convergence
|
|
265
|
+
# for i in range(100):
|
|
266
|
+
# if (self.ref_wfn is None):
|
|
267
|
+
# try:
|
|
268
|
+
# e, self.ref_wfn = psi4.energy(self.psi4method,write_orbitals=self.movecs,return_wfn=True)
|
|
269
|
+
# psi4.set_options({'d_convergence': self.d_convergence})
|
|
270
|
+
# psi4.set_options({'e_convergence': self.e_convergence})
|
|
271
|
+
# break
|
|
272
|
+
# except SCFConvergenceError:
|
|
273
|
+
# if (i==10):
|
|
274
|
+
# raise SCFConvergenceError("SCF convergence failed too many times in a row!")
|
|
275
|
+
# print("SCF convergence ({0}) ... will now increase convergence threshold by a factor of 3".format(i))
|
|
276
|
+
# tmp_d_convergence = tmp_d_convergence * 3
|
|
277
|
+
# tmp_e_convergence = tmp_e_convergence * 3
|
|
278
|
+
# psi4.set_options({'d_convergence': tmp_d_convergence})
|
|
279
|
+
# psi4.set_options({'e_convergence': tmp_e_convergence})
|
|
280
|
+
# else:
|
|
281
|
+
# try:
|
|
282
|
+
# e, self.ref_wfn = psi4.energy(self.psi4method,restart_file=self.movecs,write_orbitals=self.movecs,return_wfn=True)
|
|
283
|
+
# break
|
|
284
|
+
# except SCFConvergenceError:
|
|
285
|
+
# print("SCF convergence (0) ... will now use a SAD guess")
|
|
286
|
+
# self.ref_wfn = None
|
|
287
|
+
|
|
288
|
+
if True: # Using "run_as"
|
|
289
|
+
if (self.ref_wfn is None):
|
|
290
|
+
self.keywords["scf; vectors "] = " output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
291
|
+
self.keywords["dft; vectors "] = " output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
292
|
+
|
|
293
|
+
else:
|
|
294
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
295
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
296
|
+
|
|
297
|
+
print(self.method, self.basis_set, chemist_sys)
|
|
298
|
+
print(self.model)
|
|
299
|
+
print(self.keywords)
|
|
300
|
+
|
|
301
|
+
# self.mm.change_input(self.method + " EnergyAndGradient", 'keywords', self.keywords) # TEMPORARILY COMMENTED OUT
|
|
302
|
+
f = self.mm.run_as(simde.EnergyNuclearGradientStdVectorD(), self.method + " EnergyAndGradient", chemist_sys, PointSetD())
|
|
303
|
+
e = f.pop(-1)
|
|
304
|
+
|
|
305
|
+
# self.mm.change_input(self.method, 'keywords', self.keywords)
|
|
306
|
+
# e = self.mm.run_as(simde.TotalEnergy(), self.method, chemist_sys)
|
|
307
|
+
self.ref_wfn = True
|
|
308
|
+
|
|
309
|
+
# self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
310
|
+
# self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
311
|
+
# self.mm.change_input(self.method + " Gradient", 'keywords', self.keywords)
|
|
312
|
+
|
|
313
|
+
# f = self.mm.run_as(simde.EnergyNuclearGradientStdVectorD(), self.method + " Gradient", chemist_sys, PointSetD())
|
|
314
|
+
|
|
315
|
+
# f = -np.array(f).reshape(-1,3)
|
|
316
|
+
f = np.array(f).reshape(-1,3)
|
|
317
|
+
|
|
318
|
+
if False:
|
|
319
|
+
print(self.mm)
|
|
320
|
+
print(self.method, self.basis_set, chemist_sys)
|
|
321
|
+
print(self.model)
|
|
322
|
+
print(self.keywords)
|
|
323
|
+
print(" simde.TotalEnergy(): ", simde.TotalEnergy())
|
|
324
|
+
print("inputs of simde.TotalEnergy(): ", simde.TotalEnergy().inputs)
|
|
325
|
+
print("Now PREPARING (inputs) of the dummy module:")
|
|
326
|
+
self.mm.change_input('InitQP : samplingMethod1', 'basis set', self.basis_set)
|
|
327
|
+
# self.mm.change_submod('InitQP : samplingMethod1', 'energy submodule', simde.TotalEnergy())
|
|
328
|
+
self.mm.change_submod('InitQP : samplingMethod1', 'energy submodule', 'NWChem : SCF')
|
|
329
|
+
self.mm.change_submod('InitQP : samplingMethod1', 'gradient submodule', 'NWChem : SCF Gradient')
|
|
330
|
+
print("Now STARTING the dummy module:")
|
|
331
|
+
# qp = self.mm.run_as("", 'InitQP : samplingMethod1', chemist_sys)
|
|
332
|
+
qp = self.mm.run_as(simde.TotalEnergy(), 'InitQP : samplingMethod1', chemist_sys)
|
|
333
|
+
print("Now FINISHING the dummy module:")
|
|
334
|
+
print("QP: ", qp)
|
|
335
|
+
|
|
336
|
+
else: # Skipping "run_as"
|
|
337
|
+
if (self.ref_wfn is None):
|
|
338
|
+
self.keywords["scf; vectors "] = " output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
339
|
+
self.keywords["dft; vectors "] = " output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
340
|
+
|
|
341
|
+
e = call_qcengine(simde.TotalEnergy(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
342
|
+
self.ref_wfn = True
|
|
343
|
+
|
|
344
|
+
else:
|
|
345
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
346
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
347
|
+
|
|
348
|
+
e = call_qcengine(simde.TotalEnergy(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
349
|
+
|
|
350
|
+
self.keywords["scf; vectors "] = " input "+self.movecsSCF+" output "+self.movecsSCF+"; end" # Where to save the MOvecs
|
|
351
|
+
self.keywords["dft; vectors "] = " input "+self.movecsDFT+" output "+self.movecsDFT+"; end" # Where to save the MOvecs
|
|
352
|
+
|
|
353
|
+
# f = call_qcengine(simde.provisional.EnergyNuclearGradientD(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
354
|
+
f = call_qcengine(simde.EnergyNuclearGradientStdVectorD(), chemist_sys, 'nwchem', model=self.model, keywords=self.keywords, srun_ncores=self.n_tasks)
|
|
355
|
+
# f = -np.array(f)
|
|
356
|
+
f = np.array(f)
|
|
357
|
+
|
|
358
|
+
# Make sure that the gradient was correctly read in
|
|
359
|
+
assert len(atoms) == len(f)
|
|
360
|
+
|
|
361
|
+
# If there are 'extra' things, do them here (e.g., Mulliken analysis)
|
|
362
|
+
# if (self.mulliken > 0):
|
|
363
|
+
# self.oeprop = OEProp(self.ref_wfn)
|
|
364
|
+
# self.oeprop.add("MULLIKEN_CHARGES")
|
|
365
|
+
# self.oeprop.compute()
|
|
366
|
+
|
|
367
|
+
# Convert model units to ASE default units (eV and Ang)
|
|
368
|
+
e *= self.E_to_eV
|
|
369
|
+
f *= -self.F_to_eV_Ang
|
|
370
|
+
|
|
371
|
+
f = f.reshape(-1, 3)
|
|
372
|
+
Natoms = len(atoms)
|
|
373
|
+
print("")
|
|
374
|
+
print("NWChemEx flag 1")
|
|
375
|
+
print(Natoms)
|
|
376
|
+
print("Energy: ", e)
|
|
377
|
+
#for anAtom in atoms:
|
|
378
|
+
for i in range(Natoms):
|
|
379
|
+
anAtom = atoms[i]
|
|
380
|
+
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]))
|
|
381
|
+
print("")
|
|
382
|
+
|
|
383
|
+
self.results = {'energy': e, 'forces': f}
|
|
384
|
+
|
|
385
|
+
# Save the wavefunction every now and then if required
|
|
386
|
+
if (not (self.save_movecs_interval is None) and self.ref_wfn):
|
|
387
|
+
print("Backing up a restart...")
|
|
388
|
+
self.save_movecs_count += 1
|
|
389
|
+
if (self.save_movecs_count >= self.save_movecs_interval):
|
|
390
|
+
self.save_movecs_count = 0
|
|
391
|
+
|
|
392
|
+
coordsfile_restart = os.path.join(self.outputDIR, ".nwchemex.restart.Q.xyz")
|
|
393
|
+
momentafile_restart = os.path.join(self.outputDIR, ".nwchemex.restart.P.xyz")
|
|
394
|
+
coordsfile_restart_prev = os.path.join(self.outputDIR, ".nwchemex.restart.prev.Q.xyz")
|
|
395
|
+
momentafile_restart_prev = os.path.join(self.outputDIR, ".nwchemex.restart.prev.P.xyz")
|
|
396
|
+
|
|
397
|
+
# Back up the restart (in case there's a job kill when writing the restart file)
|
|
398
|
+
if (os.path.isfile(coordsfile_restart)):
|
|
399
|
+
shutil.copy(coordsfile_restart,coordsfile_restart_prev)
|
|
400
|
+
shutil.copy(momentafile_restart,momentafile_restart_prev)
|
|
401
|
+
if (os.path.isfile(self.movecsSCF_restart)):
|
|
402
|
+
shutil.copy(self.movecsSCF_restart,self.movecsSCF_restart_prev)
|
|
403
|
+
if (os.path.isfile(self.movecsDFT_restart)):
|
|
404
|
+
shutil.copy(self.movecsDFT_restart,self.movecsDFT_restart_prev)
|
|
405
|
+
|
|
406
|
+
if (os.path.isfile(self.movecsSCF)):
|
|
407
|
+
shutil.copy(self.movecsSCF, self.movecsSCF_restart)
|
|
408
|
+
if (os.path.isfile(self.movecsDFT)):
|
|
409
|
+
shutil.copy(self.movecsDFT, self.movecsDFT_restart)
|
|
410
|
+
|
|
411
|
+
with open(coordsfile_restart,"w") as file:
|
|
412
|
+
file.write(str(Natoms)+"\n")
|
|
413
|
+
file.write(str(e)+"\n")
|
|
414
|
+
for i in range(Natoms):
|
|
415
|
+
anAtom = atoms[i]
|
|
416
|
+
file.write("{0:2s} {1:16.8f} {2:16.8f} {3:16.8f}\n".format(anAtom.symbol,*anAtom.position))
|
|
417
|
+
|
|
418
|
+
molmomenta = atoms.get_momenta()
|
|
419
|
+
with open(momentafile_restart,"w") as file:
|
|
420
|
+
file.write(str(Natoms)+"\n")
|
|
421
|
+
file.write(str(e)+"\n")
|
|
422
|
+
for i in range(Natoms):
|
|
423
|
+
anAtom = atoms[i]
|
|
424
|
+
file.write("{0:2s} {1:16.8f} {2:16.8f} {3:16.8f}\n".format(anAtom.symbol,*molmomenta[i]))
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def get_forces(self, atoms=None, force_consistent=False):
|
|
429
|
+
forces = self.get_property('forces', atoms)
|
|
430
|
+
return forces
|
|
431
|
+
|