venuspython 1.0.3__tar.gz → 1.0.4__tar.gz

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.
Files changed (27) hide show
  1. {venuspython-1.0.3 → venuspython-1.0.4}/PKG-INFO +1 -1
  2. venuspython-1.0.4/venuspy/__init__.py +1 -0
  3. venuspython-1.0.4/venuspy/cli.py +584 -0
  4. {venuspython-1.0.3 → venuspython-1.0.4}/venuspython.egg-info/PKG-INFO +1 -1
  5. venuspython-1.0.3/venuspy/__init__.py +0 -1
  6. venuspython-1.0.3/venuspy/cli.py +0 -577
  7. {venuspython-1.0.3 → venuspython-1.0.4}/README.md +0 -0
  8. {venuspython-1.0.3 → venuspython-1.0.4}/cli.py +0 -0
  9. {venuspython-1.0.3 → venuspython-1.0.4}/pyproject.toml +0 -0
  10. {venuspython-1.0.3 → venuspython-1.0.4}/setup.cfg +0 -0
  11. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/bagelcalc.py +0 -0
  12. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/chempotpycalc.py +0 -0
  13. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/minisgdmlcalc.py +0 -0
  14. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/mopaccalc.py +0 -0
  15. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/nwchemcalc.py +0 -0
  16. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/nwchemexcalc.py +0 -0
  17. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/original_nwchemexcalc.py +0 -0
  18. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/physnetcalc.py +0 -0
  19. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/psi4calc.py +0 -0
  20. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/qcengineGAMESScalc.py +0 -0
  21. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/calc/xtbcalc.py +0 -0
  22. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/initialSampling.py +0 -0
  23. {venuspython-1.0.3 → venuspython-1.0.4}/venuspy/md.py +0 -0
  24. {venuspython-1.0.3 → venuspython-1.0.4}/venuspython.egg-info/SOURCES.txt +0 -0
  25. {venuspython-1.0.3 → venuspython-1.0.4}/venuspython.egg-info/dependency_links.txt +0 -0
  26. {venuspython-1.0.3 → venuspython-1.0.4}/venuspython.egg-info/entry_points.txt +0 -0
  27. {venuspython-1.0.3 → venuspython-1.0.4}/venuspython.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: venuspython
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: VENUSpy Initial Sampling and Molecular Dynamics
5
5
  Keywords: moleculardynamics,initialsampling
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -0,0 +1 @@
1
+ __version__ = "1.0.4"
@@ -0,0 +1,584 @@
1
+ from ase.io import read
2
+ from ase.md.verlet import VelocityVerlet
3
+ from ase import units
4
+
5
+ from ase.vibrations import Vibrations
6
+ import random
7
+
8
+ import argparse
9
+ import numpy as np
10
+ import os
11
+
12
+ # For initial sampling:
13
+ from .initialSampling import initialSampling
14
+
15
+ # For rewindrestarts:
16
+ from ase.io.extxyz import read_xyz
17
+
18
+ # For rewinds with sGDML:
19
+ from .md import regularMD, pingpongMD, smoothedMD, r2threshold
20
+
21
+
22
+
23
+ # Try importing BAGEL
24
+ try:
25
+ from .calc.bagelcalc import bagelcalculator
26
+ except ImportError:
27
+ print("WARNING: BAGEL has not been loaded ... it will not be available for initial sampling")
28
+
29
+ # Try importing psi4
30
+ try:
31
+ from .calc.psi4calc import psi4calculator
32
+ except ImportError:
33
+ print("WARNING: psi4 has not been loaded ... it will not be available for initial sampling")
34
+
35
+ # Try importing xtb (fast, semi-empirical DFT):
36
+ try:
37
+ # from tblite.ase import TBLite
38
+ from .calc.xtbcalc import TBLite
39
+ except ImportError:
40
+ print("WARNING: xtb has not been loaded ... it will not be available for initial sampling")
41
+
42
+ # Try import NWChem (not NWChemEx)
43
+ try:
44
+ from .calc.nwchemcalc import nwchemcalculator
45
+ except ImportError:
46
+ print("WARNING: NWChem has not been loaded ... it will not be available for initial sampling")
47
+
48
+ # Try importing NWChemEx
49
+ try:
50
+ from .calc.nwchemexcalc import nwchemexcalculator
51
+ except ImportError:
52
+ print("WARNING: NWChemEx has not been loaded ... it will not be available for initial sampling")
53
+
54
+ # Try importing QCEngine/GAMESS
55
+ try:
56
+ from .calc.qcengineGAMESScalc import qcengineGAMESScalculator
57
+ except ImportError:
58
+ print("WARNING: QCEngine/GAMESS has not been loaded ... it will not be available for initial sampling")
59
+
60
+ # Try importing sGDML
61
+ try:
62
+ import sgdml
63
+ from sgdml.train import GDMLTrain
64
+ from sgdml.predict import GDMLPredict
65
+ from sgdml.intf.ase_calc import SGDMLCalculator
66
+
67
+ from .calc.minisgdmlcalc import miniSGDMLCalculator
68
+
69
+ except ImportError:
70
+ print("WARNING: sGDML has not been loaded ... it will not be available for initial sampling")
71
+
72
+ # Try importing chempotpy
73
+ try:
74
+ from .calc.chempotpycalc import chempotpyCalculator
75
+ except ImportError:
76
+ print("WARNING: chempotpy has not been loaded ... it will not be available for initial sampling")
77
+
78
+ # Try importing Schnet
79
+ try:
80
+ import schnetpack as spk
81
+ import torch
82
+ except ImportError:
83
+ print("WARNING: Schnet has not been loaded ... it will not be available for initial sampling")
84
+
85
+ # Try importing Physnet
86
+ try:
87
+ from .calc.physnetcalc import PNCalculator
88
+ except ImportError:
89
+ print("WARNING: Physnet has not been loaded ... it will not be available for initial sampling")
90
+
91
+
92
+
93
+ ###################################################
94
+
95
+ # Define global constants up here in the correct
96
+ # units so that internally, everything uses:
97
+ # Energy: eV
98
+ # Distance: Angstrom
99
+ # Mass: Dalton
100
+
101
+ # global r2threshold
102
+
103
+ ###################################################
104
+
105
+ def main():
106
+
107
+ parser = argparse.ArgumentParser(description="Do a single MD trajectory using a initial geometry (and momenta) and a sGDML model",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
108
+ parser.add_argument("initialGeometryFile", type=str, help="XYZ file with initial geometry; if initial conditions are sampled in the script, then this argument is required but is just an example XYZ")
109
+ parser.add_argument("PESinputFile", type=str, help="PES input file (may be a psi4 input file or a sGDML .npz model)")
110
+ parser.add_argument("outputDir", type=str, help="Directory to output stuff in")
111
+ parser.add_argument("--isotopeMassesFile", type=str, help="Change masses of specific atoms e.g. like isotopic substitution", default=None)
112
+ parser.add_argument("--rewindrestartFile", type=str, help="EXYZ file of a previous trajectory to rewind-restart from",default=None)
113
+ parser.add_argument("--rewindrestartEnergyThreshold", type=float, help="The energy threshold for allowable energy jumps to rewind-restart from",default=0.50)
114
+ parser.add_argument("--rewindrestartNskip", type=int, help="The number of frames at the end of the trajectory to skip possible restarts from",default=0)
115
+ parser.add_argument("--initialMomentaFile", type=str, help="XYZ file with initial momenta")
116
+ parser.add_argument("--atomsInFirstGroup", type=str, help="String with atoms which are in first group of atoms, separated by spaces")
117
+ parser.add_argument("--collisionEnergy", type=float, help="Collision energy in kcal/mol")
118
+ parser.add_argument("--impactParameter", type=float, help="Impact parameter in Angstrom")
119
+ parser.add_argument("--centerOfMassDistance", type=float, help="Distance between the two molecules' centers of mass in Angstrom")
120
+ parser.add_argument('--optimize', type=bool, default=True)
121
+ parser.add_argument("--production", type=int, help="Supply number of steps for a production run")
122
+ parser.add_argument("--interval", type=int, help="How often to print out the energy")
123
+ parser.add_argument("--time_step", type=float, help="The time step in fs for a production run")
124
+ parser.add_argument("--MDtype", type=str, help="The type of molecular dynamics to do: 'regular', 'pingpong', or 'smoothed' with sGDML", default="regular")
125
+ parser.add_argument("--Nrewindsteps", type=int, help="The number of steps to use MLMD for when smoothing",default=4)
126
+ parser.add_argument("--dEmax", type=float, help="The maximum change in total energy allowed between consecutive steps",default=1.0)
127
+ parser.add_argument("--Edriftmax", type=float, help="The maximum change in total energy allowed from start to end",default=1.5)
128
+ parser.add_argument("--E0", type=float, help="The initial total energy to track the drift in total energy (e.g. if the trajectory is being restarted)",default=None)
129
+ parser.add_argument("--n_threads", type=int, help="The number of threads to ask psi4 to use")
130
+
131
+ parser.add_argument("--INITQPa", type=str, help="Initial sampling method for atoms in first group ('semiclassical', 'microcanonical', 'thermal', or None)", default="")
132
+ parser.add_argument("--NVIBa", type=int, help="Vibrational quantum number of atoms in first group (supply if using the 'semiclassical' initial sampling)")
133
+ parser.add_argument("--NROTa", type=int, help="Rotational quantum number of atoms in first group (supply if using the 'semiclassical' initial sampling)")
134
+ parser.add_argument("--EVIBa", type=float, help="Vibrational energy of atoms in first group (supply if using the 'microcanonical' initial sampling)")
135
+ parser.add_argument("--EROTa", type=float, help="Rotational energy of atoms in first group (supply if using the 'microcanonical' initial sampling)")
136
+ parser.add_argument("--TVIBa", type=float, help="Vibrational temperature of atoms in first group (supply if using the 'thermal' initial sampling)")
137
+ parser.add_argument("--TROTa", type=float, help="Rotational temperature of atoms in first group (supply if using the 'thermal' initial sampling)")
138
+
139
+ parser.add_argument("--INITQPb", type=str, help="Initial sampling method for atoms in second group ('semiclassical', 'microcanonical', 'thermal', or None)", default="")
140
+ parser.add_argument("--NVIBb", type=int, help="Vibrational quantum number of atoms in second group (supply if using the 'semiclassical' initial sampling)")
141
+ parser.add_argument("--NROTb", type=int, help="Rotational quantum number of atoms in second group (supply if using the 'semiclassical' initial sampling)")
142
+ parser.add_argument("--EVIBb", type=float, help="Vibrational energy of atoms in second group (supply if using the 'microcanonical' initial sampling)")
143
+ parser.add_argument("--EROTb", type=float, help="Rotational energy of atoms in second group (supply if using the 'microcanonical' initial sampling)")
144
+ parser.add_argument("--TVIBb", type=float, help="Vibrational temperature of atoms in second group (supply if using the 'thermal' initial sampling)")
145
+ parser.add_argument("--TROTb", type=float, help="Rotational temperature of atoms in second group (supply if using the 'thermal' initial sampling)")
146
+ args = vars(parser.parse_args())
147
+
148
+ ########################################################################################
149
+
150
+ # A function to print the potential, kinetic and total energy
151
+ def printenergy(a,step,energyflag):
152
+ if ("ERROR" in energyflag):
153
+ epot = 0.0
154
+ ekin = a.get_kinetic_energy() / (units.kcal/units.mol)
155
+ print('@Epot = %.3f Ekin = %.3f (T=%3.0fK) '
156
+ 'Etot = %.3f kcal/mol Step = %8d %s' % (epot, ekin, ekin / (len(a) * 1.5 * 8.617281e-5), epot + ekin, step, energyflag))
157
+ else:
158
+ epot = a.get_potential_energy() / (units.kcal/units.mol)
159
+ ekin = a.get_kinetic_energy() / (units.kcal/units.mol)
160
+ print('@Epot = %.3f Ekin = %.3f (T=%3.0fK) '
161
+ 'Etot = %.3f kcal/mol Step = %8d %s' % (epot, ekin, ekin / (len(a) * 1.5 * 8.617281e-5), epot + ekin, step, energyflag))
162
+
163
+ ########################################################################################
164
+
165
+ # Get the various arguments
166
+ Qfile = args["initialGeometryFile"]
167
+ input_path = args["PESinputFile"]
168
+ output_path = args["outputDir"]
169
+
170
+ rrQPfile = args["rewindrestartFile"]
171
+ rrQPdEmax = args["rewindrestartEnergyThreshold"]
172
+ rrNskip = args["rewindrestartNskip"]
173
+
174
+ Pfile = args["initialMomentaFile"]
175
+ atomsInFirstGroup = args["atomsInFirstGroup"]
176
+ ce = args["collisionEnergy"]
177
+ b = args["impactParameter"]
178
+ dCM = args["centerOfMassDistance"]
179
+
180
+ isotopeMassesFile = args["isotopeMassesFile"]
181
+ Nsteps = args["production"]
182
+ Nprint = args["interval"]
183
+ dt = args["time_step"]
184
+
185
+ MDtype = args["MDtype"]
186
+ dEmax = args["dEmax"]
187
+ Edriftmax = args["Edriftmax"]
188
+ E0= args["E0"]
189
+ Nrewindsteps = args["Nrewindsteps"]
190
+
191
+ optimize_flag = args["optimize"]
192
+
193
+ if ((Nsteps is None) or (Nprint is None) or (dt is None)):
194
+ raise ValueError("For MD, need to specify these three: --production --interval --time_step")
195
+
196
+ n_threads = args["n_threads"]
197
+ if (n_threads is None): n_threads = 1
198
+
199
+ samplingMethod = [ args["INITQPa"], args["INITQPb"] ]
200
+ vibrationSampling = []
201
+ rotationSampling = []
202
+ if (samplingMethod[0] == "semiclassical"):
203
+ vibrationSampling.append(args["NVIBa"])
204
+ rotationSampling.append(args["NROTa"])
205
+ elif ("microcanonical" in samplingMethod[0]):
206
+ vibrationSampling.append(args["EVIBa"])
207
+ rotationSampling.append(args["EROTa"])
208
+ else:
209
+ vibrationSampling.append(args["TVIBa"])
210
+ rotationSampling.append(args["TROTa"])
211
+ if (samplingMethod[1] == "semiclassical"):
212
+ vibrationSampling.append(args["NVIBb"])
213
+ rotationSampling.append(args["NROTb"])
214
+ elif ("microcanonical" in samplingMethod[1]):
215
+ vibrationSampling.append(args["EVIBb"])
216
+ rotationSampling.append(args["EROTb"])
217
+ else:
218
+ vibrationSampling.append(args["TVIBb"])
219
+ rotationSampling.append(args["TROTb"])
220
+
221
+ # Note:
222
+ # Right now, all arguments are mandatory (even though this does
223
+ # not raise a warning) except for isotopeMassesFile
224
+
225
+ # Adjust the maximum interatomic distance allowed
226
+ # for the simulation
227
+ if ((b is not None) and (dCM is not None) and (1.2*(b**2 + dCM**2) > r2threshold)):
228
+ r2threshold = 1.2*(b**2 + dCM**2)
229
+
230
+ ########################################################################################
231
+
232
+ # Look at the input file name to guess its identity
233
+ try_bagel = False
234
+ try_psi4 = False
235
+ try_xtb = False
236
+ try_mopac = False
237
+ try_chempotpy = False
238
+ try_nwchem = False
239
+ try_nwchemex = False
240
+ try_physnet = False
241
+ try_schnet = False
242
+ try_sgdml = False
243
+ try_qcenginegamess = False
244
+ if (input_path.endswith(('.npz',))):
245
+
246
+ print("Input file '"+input_path+"' looks like a sGDML file so will attempt to read it in as such...")
247
+ try:
248
+ calc = SGDMLCalculator(input_path)
249
+ try_sgdml = True
250
+ except:
251
+ print(" Could not load file '"+input_path+"' as a sGDML model!")
252
+ try_psi4 = True
253
+
254
+ elif (input_path.endswith(('.physnet.config',))):
255
+ print("Input file '"+input_path+"' looks like a PhysNet config file so will attempt to read it in as such...")
256
+
257
+ if True:
258
+ tmp_mol = read(Qfile)
259
+ calc = PNCalculator(input_path,tmp_mol)
260
+ try_physnet = True
261
+
262
+ elif (input_path.endswith(('.bagel',))):
263
+ try_bagel = True
264
+
265
+ elif (input_path.endswith(('.psi4',))):
266
+ try_psi4 = True
267
+
268
+ elif (input_path.endswith(('.nwchem',))):
269
+ try_nwchem = True
270
+
271
+ elif (input_path.endswith(('.chempotpy',))):
272
+ try_chempotpy = True
273
+
274
+ elif (input_path.endswith(('.xtb',))):
275
+ try_xtb = True
276
+
277
+ elif (input_path.endswith(('.mopac',))):
278
+ try_mopac = True
279
+
280
+ elif (input_path.endswith(('.gamess.qcengine',))):
281
+ try_qcenginegamess = True
282
+
283
+ elif (input_path.endswith(('.nwchemex',))):
284
+ try_nwchemex = True
285
+
286
+ else:
287
+ try_schnet = True
288
+
289
+
290
+
291
+
292
+ if (try_schnet):
293
+
294
+ # Initialize the ML ase interface
295
+
296
+ # To accomodate for the older versions of numpy used in Schnet==1.0
297
+ np.int = np.int32
298
+ np.float = np.float64
299
+ np.bool = np.bool_
300
+
301
+ calc = spk.interfaces.SpkCalculator(
302
+ input_path,
303
+ device="cpu",
304
+ energy="energy", # Name of energies
305
+ forces="forces", # Name of forces
306
+ energy_units="kcal/mol",
307
+ forces_units="kcal/mol/A",
308
+ neighbor_list=spk.transform.ASENeighborList(5.0),
309
+ )
310
+
311
+
312
+ if (try_bagel):
313
+ print("Reading input file '"+input_path+"' as a BAGEL input file...")
314
+ calc = bagelcalculator(custominputfile=input_path,command='mpirun /mnt/lustre/koa/koastore/rsun_group/camels/BAGEL_1_AV/BAGEL/bin/BAGEL bagel0.json > bagel0.out')
315
+
316
+ # calc.restarts_max = 2 # Max number of allowable SCF restarts
317
+
318
+ # To conform to VENUS, we are going to keep the units
319
+ # in kcal/mol and Angstroms (which the model was
320
+ # originally trained on)
321
+ calc.E_to_eV = units.Ha
322
+ calc.Ang_to_R = units.Ang
323
+ calc.F_to_eV_Ang = (units.Ha / units.Bohr)
324
+
325
+ if (try_psi4):
326
+ print("Reading input file '"+input_path+"' as a psi4 input file...")
327
+ calc = psi4calculator(input_path,n_threads=n_threads)
328
+
329
+ calc.restarts_max = 2 # Max number of allowable SCF restarts
330
+
331
+ # To conform to VENUS, we are going to keep the units
332
+ # in kcal/mol and Angstroms (which the model was
333
+ # originally trained on)
334
+ calc.E_to_eV = units.Ha
335
+ calc.Ang_to_R = units.Ang
336
+ calc.F_to_eV_Ang = (units.Ha / units.Bohr)
337
+
338
+ if (try_xtb):
339
+ print("Reading input file '"+input_path+"' as a xtb input file...")
340
+ calc = TBLite(input_path)
341
+
342
+ if (try_qcenginegamess):
343
+ print("Reading input file '"+input_path+"' as a QCEngine/GAMESS input file...")
344
+ calc = qcengineGAMESScalculator(input_path,n_threads=n_threads)
345
+
346
+ # To conform to VENUS, we are going to keep the units
347
+ # in kcal/mol and Angstroms (which the model was
348
+ # originally trained on)
349
+ calc.E_to_eV = units.Ha
350
+ calc.Ang_to_R = (units.Ang / units.Bohr)
351
+ calc.F_to_eV_Ang = (units.Ha / units.Bohr)
352
+
353
+ if (try_nwchemex):
354
+ print("Reading input file '"+input_path+"' as a NWChemEx input file...")
355
+ calc = nwchemexcalculator(input_path,output_path=output_path,n_threads=n_threads)
356
+
357
+ # To conform to VENUS, we are going to keep the units
358
+ # in kcal/mol and Angstroms (which the model was
359
+ # originally trained on)
360
+ calc.E_to_eV = units.Ha
361
+ calc.Ang_to_R = (units.Ang / units.Bohr)
362
+ calc.F_to_eV_Ang = (units.Ha / units.Bohr)
363
+
364
+ if (try_nwchem):
365
+ print("Reading input file '"+input_path+"' as a NWChem (not NWChemEx) input file...")
366
+ calc = nwchemcalculator(input_path,output_path=output_path,n_threads=n_threads)
367
+
368
+ # To conform to VENUS, we are going to keep the units
369
+ # in kcal/mol and Angstroms (which the model was
370
+ # originally trained on)
371
+ calc.E_to_eV = 1.0 # units.Ha
372
+ calc.Ang_to_R = 1.0 # (units.Ang / units.Bohr)
373
+ calc.F_to_eV_Ang = 1.0 # (units.Ha / units.Bohr)
374
+
375
+ if (try_chempotpy):
376
+
377
+ print("Reading input file '"+input_path+"' as a chempotpy input file...")
378
+
379
+ # Read the input file
380
+ with open(input_path, 'r') as f:
381
+
382
+ totallines = []
383
+ totalentries = []
384
+ for line in f:
385
+ strippedline=" ".join(line.split())
386
+ entries = strippedline.split(" ")
387
+ totallines.append(line)
388
+ totalentries = totalentries + entries
389
+
390
+ calc = chempotpyCalculator(totallines[0])
391
+ strippedline=" ".join(line.split()[2:])
392
+ print("Single state: {:s} - Chempotpy input: {:s}".format(totalentries[0],strippedline))
393
+
394
+ # Note, different chempotpy PES have different maximum allowed distances
395
+ # For O3 surfaces, 100 A is okay (= 2 * 50 A)
396
+ initialSampling.dSEPARATED = 50.0
397
+
398
+ # For now, just use a different distance threshold too
399
+ r2threshold = (dCM + 5.0) * (dCM + 5.0)
400
+
401
+
402
+ if (try_mopac):
403
+ print("Reading input file '"+input_path+"' as a MOPAC input file...")
404
+ calc = mopaccalculator(input_path,output_path=output_path)
405
+
406
+ # To conform to VENUS, we are going to keep the units
407
+ # in kcal/mol and Angstroms (which the model was
408
+ # originally trained on)
409
+ calc.E_to_eV = 1.0 # units.Ha
410
+ calc.Ang_to_R = 1.0 # (units.Ang / units.Bohr)
411
+ calc.F_to_eV_Ang = 1.0 # (units.Ha / units.Bohr)
412
+
413
+
414
+ # Read in the geometry; set it in the "calculator"
415
+ mol = read(Qfile)
416
+ mol.set_calculator(calc)
417
+ mol.calc = calc
418
+ mol._calc = calc
419
+
420
+ # Get the output trajectory file ready
421
+ trajfile = os.path.join(output_path, "production.traj")
422
+
423
+ # If the masses are given, update the masses
424
+ # Note: this must be done BEFORE setting the momenta
425
+ if not (isotopeMassesFile is None):
426
+ massFile = open(isotopeMassesFile,"r")
427
+ newMasses = massFile.readlines()
428
+ massFile.close()
429
+ if (len(newMasses) != len(mol)): #.masses)):
430
+ raise ValueError("Number of masses provided in the isotope mass file does not match the input XYZ")
431
+ mol.set_masses([float(i) for i in newMasses])
432
+
433
+ # If a rewind-restart file is given, read in the coordinates (Q),
434
+ # momenta (P), and energies, for a possible restart
435
+ if not (rrQPfile is None):
436
+
437
+ print("REWIND-RESTARTING using this file: " + rrQPfile)
438
+
439
+ # Look at the last 1500 frames to restart from (but skip the last rrNskip)
440
+ rrQPfilehandle = open(rrQPfile)
441
+ if (rrNskip <= 0):
442
+ rrmols = list(read_xyz(rrQPfilehandle,slice(-1500,None)))
443
+ rrNskip = 0
444
+ else:
445
+ rrmols = list(read_xyz(rrQPfilehandle,slice(-(1500+rrNskip),-rrNskip)))
446
+
447
+ rrQPflag = True
448
+ Nconsecutivegoodframes = 0
449
+ rrmols.reverse() # Go from the most-recent to least-recent
450
+ for i,rrmol in enumerate(rrmols):
451
+ mol.set_positions(rrmol.get_positions())
452
+ mol.set_velocities(rrmol.get_velocities())
453
+ mol.set_momenta(rrmol.get_momenta())
454
+
455
+ # Compare the original and restarted potential energies
456
+ E_original = rrmol.calc.results['energy']
457
+ try:
458
+ Nconsecutivegoodframes += 1
459
+ E_restart = mol.get_potential_energy()
460
+ dE = abs(E_original - E_restart) / (units.kcal/units.mol)
461
+ print("REWIND-RESTARTING sees that the %d-th to last frame (1-th to last = last frame) has original energy %.3f and restart energy %.3f kcal/mol"
462
+ % (rrNskip+i+1, E_original / (units.kcal/units.mol), E_restart / (units.kcal/units.mol)))
463
+ except:
464
+ Nconsecutivegoodframes = 0
465
+ dE = rrQPdEmax * 2
466
+ print("REWIND-RESTARTING sees that the %d-th to last frame (1-th to last = last frame) has original energy %.3f and restart energy NaN kcal/mol"
467
+ % (rrNskip+i+1, E_original / (units.kcal/units.mol)))
468
+
469
+ # If they agree within the threshold, then go ahead with the restart
470
+ if (dE < rrQPdEmax):
471
+
472
+ # For a smoothed MD simulation, we need a few frames at the start to buffer over
473
+ if (Nconsecutivegoodframes < 10):
474
+ if (MDtype == "smoothed"): continue
475
+
476
+ rrQPflag = False
477
+ print("REWIND-RESTARTING accepts using the %d-th to last frame! (1-th to last = last frame)" % (rrNskip+i+1,))
478
+ break
479
+
480
+ if (rrQPflag):
481
+ raise ValueError("REWIND-RESTARTING failed ... no acceptable frames to restart from")
482
+
483
+ # If a momenta file is given, read in the momenta
484
+ # Read it in as a geometry, and then set it into the molecule
485
+ elif not (Pfile is None):
486
+ frame = read(Pfile)
487
+ p = [atom.position for atom in frame]
488
+ mol.set_momenta(p)
489
+
490
+ masses=mol.get_masses()
491
+ v = [p[i]/masses[i] for i in range(len(p))]
492
+ mol.set_velocities(v)
493
+
494
+ # If there is no momenta file, then do initial sampling
495
+ else:
496
+
497
+ Natoms = len(mol)
498
+
499
+ # If no atoms are specified to be in the first group,
500
+ # assume that this is a unimolecular sampling
501
+ if (atomsInFirstGroup is None):
502
+ atomsInFirstGroup = range(Natoms)
503
+
504
+ atomsInFirstGroup = [int(i)-1 for i in atomsInFirstGroup.split()]
505
+
506
+ atomsInSecondGroup = []
507
+ for i in range(Natoms):
508
+ if (i not in atomsInFirstGroup): atomsInSecondGroup.append(i)
509
+
510
+ if ((len(atomsInFirstGroup) > 0) and (len(atomsInSecondGroup) > 0)):
511
+ bimolecular_flag = True
512
+ if ((ce is None) or (b is None) or (dCM is None)):
513
+ raise ValueError("Lacking an argument for bimolecular sampling (collision energy, impact parameter, of center of mass distance)")
514
+ else:
515
+ bimolecular_flag = False
516
+
517
+ print("")
518
+ print("GEOMETRY INPUT")
519
+ print(" Input geometry file: ", Qfile)
520
+ print("Atoms in first group: ", atomsInFirstGroup)
521
+ print("Atoms in second group: ", atomsInSecondGroup)
522
+ print("SAMPLING INPUT")
523
+ print(" Input momenta file: ", Pfile)
524
+ if (Pfile is None):
525
+ print(" Optimize molecules? ", optimize_flag)
526
+ print(" Group A sampling method: ", samplingMethod[0])
527
+ print(" Group A vibration: ", vibrationSampling[0])
528
+ print(" Group A rotation: ", rotationSampling[0])
529
+ print(" Group B sampling method: ", samplingMethod[1])
530
+ print(" Group B vibration: ", vibrationSampling[1])
531
+ print(" Group B rotation: ", rotationSampling[1])
532
+ print(" Impact parameter (A): ", b)
533
+ print(" Initial separation (A): ", dCM)
534
+ print(" Collsion energy (kcal/mol): ", ce)
535
+ else:
536
+ print(" Input momenta file: ", Pfile)
537
+
538
+ print("##############################################################")
539
+ print("")
540
+
541
+ # Sample the internal positions and momenta of each of
542
+ # the two molecules
543
+ sampler = initialSampling(mol,atomsInFirstGroup,optimize=optimize_flag,
544
+ optimization_file=os.path.join(output_path, "optimization.traj"),
545
+ samplingMethodA=samplingMethod[0],vibrationalSampleA=vibrationSampling[0],rotationalSampleA=rotationSampling[0],
546
+ samplingMethodB=samplingMethod[1],vibrationalSampleB=vibrationSampling[1],rotationalSampleB=rotationSampling[1])
547
+
548
+ print("Sampling internal degrees of freedom...")
549
+ sampler.sampleRelativeQP()
550
+
551
+ if (bimolecular_flag):
552
+ print("Sampling relative degrees of freedom...")
553
+ sampler.sampleAbsoluteQP(ce,dCM=dCM,b=b)
554
+
555
+ else:
556
+ sampler.centerMolecule(range(Natoms))
557
+
558
+ ########################################################################################
559
+
560
+ if (MDtype == "regular"):
561
+
562
+ MDgen = regularMD(mol,trajfile,dt,Nprint=Nprint)
563
+
564
+ elif (MDtype == "pingpong"):
565
+
566
+ MDgen = pingpongMD(mol,trajfile,dt,Nprint=Nprint)
567
+
568
+ elif (MDtype == "smoothed"):
569
+
570
+ # MDgen = smoothedMD(mol,trajfile,dt,Nprint=Nprint,Nrewindsteps=Nrewindsteps,dEmax=dEmax,Edriftmax=Edriftmax)
571
+ MDgen = smoothedMD(mol,trajfile,dt,Nprint=Nprint,Nrewindsteps=Nrewindsteps,dEmax=dEmax,Edriftmax=Edriftmax,E0=E0,n_threads=n_threads)
572
+
573
+ else:
574
+ raise ValueError("MD type '"+MDtype+"' is not valid! Exiting...")
575
+
576
+ MDgen.production(Nsteps)
577
+
578
+
579
+
580
+
581
+ if __name__ == "__main__":
582
+ main()
583
+
584
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: venuspython
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: VENUSpy Initial Sampling and Molecular Dynamics
5
5
  Keywords: moleculardynamics,initialsampling
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -1 +0,0 @@
1
- __version__ = "1.0.3"
@@ -1,577 +0,0 @@
1
- from ase.io import read
2
- from ase.md.verlet import VelocityVerlet
3
- from ase import units
4
-
5
- from ase.vibrations import Vibrations
6
- import random
7
-
8
- import argparse
9
- import numpy as np
10
- import os
11
-
12
- # For initial sampling:
13
- from .initialSampling import initialSampling
14
-
15
- # For rewindrestarts:
16
- from ase.io.extxyz import read_xyz
17
-
18
- # For rewinds with sGDML:
19
- from .md import regularMD, pingpongMD, smoothedMD, r2threshold
20
-
21
-
22
-
23
- # Try importing BAGEL
24
- try:
25
- from .calc.bagelcalc import bagelcalculator
26
- except ImportError:
27
- print("WARNING: BAGEL has not been loaded ... it will not be available for initial sampling")
28
-
29
- # Try importing psi4
30
- try:
31
- from .calc.psi4calc import psi4calculator
32
- except ImportError:
33
- print("WARNING: psi4 has not been loaded ... it will not be available for initial sampling")
34
-
35
- # Try importing xtb (fast, semi-empirical DFT):
36
- try:
37
- # from tblite.ase import TBLite
38
- from .calc.xtbcalc import TBLite
39
- except ImportError:
40
- print("WARNING: xtb has not been loaded ... it will not be available for initial sampling")
41
-
42
- # Try import NWChem (not NWChemEx)
43
- try:
44
- from .calc.nwchemcalc import nwchemcalculator
45
- except ImportError:
46
- print("WARNING: NWChem has not been loaded ... it will not be available for initial sampling")
47
-
48
- # Try importing NWChemEx
49
- try:
50
- from .calc.nwchemexcalc import nwchemexcalculator
51
- except ImportError:
52
- print("WARNING: NWChemEx has not been loaded ... it will not be available for initial sampling")
53
-
54
- # Try importing QCEngine/GAMESS
55
- try:
56
- from .calc.qcengineGAMESScalc import qcengineGAMESScalculator
57
- except ImportError:
58
- print("WARNING: QCEngine/GAMESS has not been loaded ... it will not be available for initial sampling")
59
-
60
- # Try importing sGDML
61
- try:
62
- import sgdml
63
- from sgdml.train import GDMLTrain
64
- from sgdml.predict import GDMLPredict
65
- from sgdml.intf.ase_calc import SGDMLCalculator
66
-
67
- from .calc.minisgdmlcalc import miniSGDMLCalculator
68
-
69
- except ImportError:
70
- print("WARNING: sGDML has not been loaded ... it will not be available for initial sampling")
71
-
72
- # Try importing chempotpy
73
- try:
74
- from .calc.chempotpycalc import chempotpyCalculator
75
- except ImportError:
76
- print("WARNING: chempotpy has not been loaded ... it will not be available for initial sampling")
77
-
78
- # Try importing Schnet
79
- try:
80
- import schnetpack as spk
81
- import torch
82
- except ImportError:
83
- print("WARNING: Schnet has not been loaded ... it will not be available for initial sampling")
84
-
85
- # Try importing Physnet
86
- try:
87
- from .calc.physnetcalc import PNCalculator
88
- except ImportError:
89
- print("WARNING: Physnet has not been loaded ... it will not be available for initial sampling")
90
-
91
-
92
-
93
- ###################################################
94
-
95
- # Define global constants up here in the correct
96
- # units so that internally, everything uses:
97
- # Energy: eV
98
- # Distance: Angstrom
99
- # Mass: Dalton
100
-
101
- # global r2threshold
102
-
103
- ###################################################
104
-
105
- parser = argparse.ArgumentParser(description="Do a single MD trajectory using a initial geometry (and momenta) and a sGDML model",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
106
- parser.add_argument("initialGeometryFile", type=str, help="XYZ file with initial geometry; if initial conditions are sampled in the script, then this argument is required but is just an example XYZ")
107
- parser.add_argument("PESinputFile", type=str, help="PES input file (may be a psi4 input file or a sGDML .npz model)")
108
- parser.add_argument("outputDir", type=str, help="Directory to output stuff in")
109
- parser.add_argument("--isotopeMassesFile", type=str, help="Change masses of specific atoms e.g. like isotopic substitution", default=None)
110
- parser.add_argument("--rewindrestartFile", type=str, help="EXYZ file of a previous trajectory to rewind-restart from",default=None)
111
- parser.add_argument("--rewindrestartEnergyThreshold", type=float, help="The energy threshold for allowable energy jumps to rewind-restart from",default=0.50)
112
- parser.add_argument("--rewindrestartNskip", type=int, help="The number of frames at the end of the trajectory to skip possible restarts from",default=0)
113
- parser.add_argument("--initialMomentaFile", type=str, help="XYZ file with initial momenta")
114
- parser.add_argument("--atomsInFirstGroup", type=str, help="String with atoms which are in first group of atoms, separated by spaces")
115
- parser.add_argument("--collisionEnergy", type=float, help="Collision energy in kcal/mol")
116
- parser.add_argument("--impactParameter", type=float, help="Impact parameter in Angstrom")
117
- parser.add_argument("--centerOfMassDistance", type=float, help="Distance between the two molecules' centers of mass in Angstrom")
118
- parser.add_argument('--optimize', type=bool, default=True)
119
- parser.add_argument("--production", type=int, help="Supply number of steps for a production run")
120
- parser.add_argument("--interval", type=int, help="How often to print out the energy")
121
- parser.add_argument("--time_step", type=float, help="The time step in fs for a production run")
122
- parser.add_argument("--MDtype", type=str, help="The type of molecular dynamics to do: 'regular', 'pingpong', or 'smoothed' with sGDML", default="regular")
123
- parser.add_argument("--Nrewindsteps", type=int, help="The number of steps to use MLMD for when smoothing",default=4)
124
- parser.add_argument("--dEmax", type=float, help="The maximum change in total energy allowed between consecutive steps",default=1.0)
125
- parser.add_argument("--Edriftmax", type=float, help="The maximum change in total energy allowed from start to end",default=1.5)
126
- parser.add_argument("--E0", type=float, help="The initial total energy to track the drift in total energy (e.g. if the trajectory is being restarted)",default=None)
127
- parser.add_argument("--n_threads", type=int, help="The number of threads to ask psi4 to use")
128
-
129
- parser.add_argument("--INITQPa", type=str, help="Initial sampling method for atoms in first group ('semiclassical', 'microcanonical', 'thermal', or None)", default="")
130
- parser.add_argument("--NVIBa", type=int, help="Vibrational quantum number of atoms in first group (supply if using the 'semiclassical' initial sampling)")
131
- parser.add_argument("--NROTa", type=int, help="Rotational quantum number of atoms in first group (supply if using the 'semiclassical' initial sampling)")
132
- parser.add_argument("--EVIBa", type=float, help="Vibrational energy of atoms in first group (supply if using the 'microcanonical' initial sampling)")
133
- parser.add_argument("--EROTa", type=float, help="Rotational energy of atoms in first group (supply if using the 'microcanonical' initial sampling)")
134
- parser.add_argument("--TVIBa", type=float, help="Vibrational temperature of atoms in first group (supply if using the 'thermal' initial sampling)")
135
- parser.add_argument("--TROTa", type=float, help="Rotational temperature of atoms in first group (supply if using the 'thermal' initial sampling)")
136
-
137
- parser.add_argument("--INITQPb", type=str, help="Initial sampling method for atoms in second group ('semiclassical', 'microcanonical', 'thermal', or None)", default="")
138
- parser.add_argument("--NVIBb", type=int, help="Vibrational quantum number of atoms in second group (supply if using the 'semiclassical' initial sampling)")
139
- parser.add_argument("--NROTb", type=int, help="Rotational quantum number of atoms in second group (supply if using the 'semiclassical' initial sampling)")
140
- parser.add_argument("--EVIBb", type=float, help="Vibrational energy of atoms in second group (supply if using the 'microcanonical' initial sampling)")
141
- parser.add_argument("--EROTb", type=float, help="Rotational energy of atoms in second group (supply if using the 'microcanonical' initial sampling)")
142
- parser.add_argument("--TVIBb", type=float, help="Vibrational temperature of atoms in second group (supply if using the 'thermal' initial sampling)")
143
- parser.add_argument("--TROTb", type=float, help="Rotational temperature of atoms in second group (supply if using the 'thermal' initial sampling)")
144
- args = vars(parser.parse_args())
145
-
146
- ########################################################################################
147
-
148
- # A function to print the potential, kinetic and total energy
149
- def printenergy(a,step,energyflag):
150
- if ("ERROR" in energyflag):
151
- epot = 0.0
152
- ekin = a.get_kinetic_energy() / (units.kcal/units.mol)
153
- print('@Epot = %.3f Ekin = %.3f (T=%3.0fK) '
154
- 'Etot = %.3f kcal/mol Step = %8d %s' % (epot, ekin, ekin / (len(a) * 1.5 * 8.617281e-5), epot + ekin, step, energyflag))
155
- else:
156
- epot = a.get_potential_energy() / (units.kcal/units.mol)
157
- ekin = a.get_kinetic_energy() / (units.kcal/units.mol)
158
- print('@Epot = %.3f Ekin = %.3f (T=%3.0fK) '
159
- 'Etot = %.3f kcal/mol Step = %8d %s' % (epot, ekin, ekin / (len(a) * 1.5 * 8.617281e-5), epot + ekin, step, energyflag))
160
-
161
- ########################################################################################
162
-
163
- # Get the various arguments
164
- Qfile = args["initialGeometryFile"]
165
- input_path = args["PESinputFile"]
166
- output_path = args["outputDir"]
167
-
168
- rrQPfile = args["rewindrestartFile"]
169
- rrQPdEmax = args["rewindrestartEnergyThreshold"]
170
- rrNskip = args["rewindrestartNskip"]
171
-
172
- Pfile = args["initialMomentaFile"]
173
- atomsInFirstGroup = args["atomsInFirstGroup"]
174
- ce = args["collisionEnergy"]
175
- b = args["impactParameter"]
176
- dCM = args["centerOfMassDistance"]
177
-
178
- isotopeMassesFile = args["isotopeMassesFile"]
179
- Nsteps = args["production"]
180
- Nprint = args["interval"]
181
- dt = args["time_step"]
182
-
183
- MDtype = args["MDtype"]
184
- dEmax = args["dEmax"]
185
- Edriftmax = args["Edriftmax"]
186
- E0= args["E0"]
187
- Nrewindsteps = args["Nrewindsteps"]
188
-
189
- optimize_flag = args["optimize"]
190
-
191
- if ((Nsteps is None) or (Nprint is None) or (dt is None)):
192
- raise ValueError("For MD, need to specify these three: --production --interval --time_step")
193
-
194
- n_threads = args["n_threads"]
195
- if (n_threads is None): n_threads = 1
196
-
197
- samplingMethod = [ args["INITQPa"], args["INITQPb"] ]
198
- vibrationSampling = []
199
- rotationSampling = []
200
- if (samplingMethod[0] == "semiclassical"):
201
- vibrationSampling.append(args["NVIBa"])
202
- rotationSampling.append(args["NROTa"])
203
- elif ("microcanonical" in samplingMethod[0]):
204
- vibrationSampling.append(args["EVIBa"])
205
- rotationSampling.append(args["EROTa"])
206
- else:
207
- vibrationSampling.append(args["TVIBa"])
208
- rotationSampling.append(args["TROTa"])
209
- if (samplingMethod[1] == "semiclassical"):
210
- vibrationSampling.append(args["NVIBb"])
211
- rotationSampling.append(args["NROTb"])
212
- elif ("microcanonical" in samplingMethod[1]):
213
- vibrationSampling.append(args["EVIBb"])
214
- rotationSampling.append(args["EROTb"])
215
- else:
216
- vibrationSampling.append(args["TVIBb"])
217
- rotationSampling.append(args["TROTb"])
218
-
219
- # Note:
220
- # Right now, all arguments are mandatory (even though this does
221
- # not raise a warning) except for isotopeMassesFile
222
-
223
- # Adjust the maximum interatomic distance allowed
224
- # for the simulation
225
- if ((b is not None) and (dCM is not None) and (1.2*(b**2 + dCM**2) > r2threshold)):
226
- r2threshold = 1.2*(b**2 + dCM**2)
227
-
228
- ########################################################################################
229
-
230
- # Look at the input file name to guess its identity
231
- try_bagel = False
232
- try_psi4 = False
233
- try_xtb = False
234
- try_mopac = False
235
- try_chempotpy = False
236
- try_nwchem = False
237
- try_nwchemex = False
238
- try_physnet = False
239
- try_schnet = False
240
- try_sgdml = False
241
- try_qcenginegamess = False
242
- if (input_path.endswith(('.npz',))):
243
-
244
- print("Input file '"+input_path+"' looks like a sGDML file so will attempt to read it in as such...")
245
- try:
246
- calc = SGDMLCalculator(input_path)
247
- try_sgdml = True
248
- except:
249
- print(" Could not load file '"+input_path+"' as a sGDML model!")
250
- try_psi4 = True
251
-
252
- elif (input_path.endswith(('.physnet.config',))):
253
- print("Input file '"+input_path+"' looks like a PhysNet config file so will attempt to read it in as such...")
254
-
255
- if True:
256
- tmp_mol = read(Qfile)
257
- calc = PNCalculator(input_path,tmp_mol)
258
- try_physnet = True
259
-
260
- elif (input_path.endswith(('.bagel',))):
261
- try_bagel = True
262
-
263
- elif (input_path.endswith(('.psi4',))):
264
- try_psi4 = True
265
-
266
- elif (input_path.endswith(('.nwchem',))):
267
- try_nwchem = True
268
-
269
- elif (input_path.endswith(('.chempotpy',))):
270
- try_chempotpy = True
271
-
272
- elif (input_path.endswith(('.xtb',))):
273
- try_xtb = True
274
-
275
- elif (input_path.endswith(('.mopac',))):
276
- try_mopac = True
277
-
278
- elif (input_path.endswith(('.gamess.qcengine',))):
279
- try_qcenginegamess = True
280
-
281
- elif (input_path.endswith(('.nwchemex',))):
282
- try_nwchemex = True
283
-
284
- else:
285
- try_schnet = True
286
-
287
-
288
-
289
-
290
- if (try_schnet):
291
-
292
- # Initialize the ML ase interface
293
-
294
- # To accomodate for the older versions of numpy used in Schnet==1.0
295
- np.int = np.int32
296
- np.float = np.float64
297
- np.bool = np.bool_
298
-
299
- calc = spk.interfaces.SpkCalculator(
300
- input_path,
301
- device="cpu",
302
- energy="energy", # Name of energies
303
- forces="forces", # Name of forces
304
- energy_units="kcal/mol",
305
- forces_units="kcal/mol/A",
306
- neighbor_list=spk.transform.ASENeighborList(5.0),
307
- )
308
-
309
-
310
- if (try_bagel):
311
- print("Reading input file '"+input_path+"' as a BAGEL input file...")
312
- calc = bagelcalculator(custominputfile=input_path,command='mpirun /mnt/lustre/koa/koastore/rsun_group/camels/BAGEL_1_AV/BAGEL/bin/BAGEL bagel0.json > bagel0.out')
313
-
314
- # calc.restarts_max = 2 # Max number of allowable SCF restarts
315
-
316
- # To conform to VENUS, we are going to keep the units
317
- # in kcal/mol and Angstroms (which the model was
318
- # originally trained on)
319
- calc.E_to_eV = units.Ha
320
- calc.Ang_to_R = units.Ang
321
- calc.F_to_eV_Ang = (units.Ha / units.Bohr)
322
-
323
- if (try_psi4):
324
- print("Reading input file '"+input_path+"' as a psi4 input file...")
325
- calc = psi4calculator(input_path,n_threads=n_threads)
326
-
327
- calc.restarts_max = 2 # Max number of allowable SCF restarts
328
-
329
- # To conform to VENUS, we are going to keep the units
330
- # in kcal/mol and Angstroms (which the model was
331
- # originally trained on)
332
- calc.E_to_eV = units.Ha
333
- calc.Ang_to_R = units.Ang
334
- calc.F_to_eV_Ang = (units.Ha / units.Bohr)
335
-
336
- if (try_xtb):
337
- print("Reading input file '"+input_path+"' as a xtb input file...")
338
- calc = TBLite(input_path)
339
-
340
- if (try_qcenginegamess):
341
- print("Reading input file '"+input_path+"' as a QCEngine/GAMESS input file...")
342
- calc = qcengineGAMESScalculator(input_path,n_threads=n_threads)
343
-
344
- # To conform to VENUS, we are going to keep the units
345
- # in kcal/mol and Angstroms (which the model was
346
- # originally trained on)
347
- calc.E_to_eV = units.Ha
348
- calc.Ang_to_R = (units.Ang / units.Bohr)
349
- calc.F_to_eV_Ang = (units.Ha / units.Bohr)
350
-
351
- if (try_nwchemex):
352
- print("Reading input file '"+input_path+"' as a NWChemEx input file...")
353
- calc = nwchemexcalculator(input_path,output_path=output_path,n_threads=n_threads)
354
-
355
- # To conform to VENUS, we are going to keep the units
356
- # in kcal/mol and Angstroms (which the model was
357
- # originally trained on)
358
- calc.E_to_eV = units.Ha
359
- calc.Ang_to_R = (units.Ang / units.Bohr)
360
- calc.F_to_eV_Ang = (units.Ha / units.Bohr)
361
-
362
- if (try_nwchem):
363
- print("Reading input file '"+input_path+"' as a NWChem (not NWChemEx) input file...")
364
- calc = nwchemcalculator(input_path,output_path=output_path,n_threads=n_threads)
365
-
366
- # To conform to VENUS, we are going to keep the units
367
- # in kcal/mol and Angstroms (which the model was
368
- # originally trained on)
369
- calc.E_to_eV = 1.0 # units.Ha
370
- calc.Ang_to_R = 1.0 # (units.Ang / units.Bohr)
371
- calc.F_to_eV_Ang = 1.0 # (units.Ha / units.Bohr)
372
-
373
- if (try_chempotpy):
374
-
375
- print("Reading input file '"+input_path+"' as a chempotpy input file...")
376
-
377
- # Read the input file
378
- with open(input_path, 'r') as f:
379
-
380
- totallines = []
381
- totalentries = []
382
- for line in f:
383
- strippedline=" ".join(line.split())
384
- entries = strippedline.split(" ")
385
- totallines.append(line)
386
- totalentries = totalentries + entries
387
-
388
- calc = chempotpyCalculator(totallines[0])
389
- strippedline=" ".join(line.split()[2:])
390
- print("Single state: {:s} - Chempotpy input: {:s}".format(totalentries[0],strippedline))
391
-
392
- # Note, different chempotpy PES have different maximum allowed distances
393
- # For O3 surfaces, 100 A is okay (= 2 * 50 A)
394
- initialSampling.dSEPARATED = 50.0
395
-
396
- # For now, just use a different distance threshold too
397
- r2threshold = (dCM + 5.0) * (dCM + 5.0)
398
-
399
-
400
- if (try_mopac):
401
- print("Reading input file '"+input_path+"' as a MOPAC input file...")
402
- calc = mopaccalculator(input_path,output_path=output_path)
403
-
404
- # To conform to VENUS, we are going to keep the units
405
- # in kcal/mol and Angstroms (which the model was
406
- # originally trained on)
407
- calc.E_to_eV = 1.0 # units.Ha
408
- calc.Ang_to_R = 1.0 # (units.Ang / units.Bohr)
409
- calc.F_to_eV_Ang = 1.0 # (units.Ha / units.Bohr)
410
-
411
-
412
- # Read in the geometry; set it in the "calculator"
413
- mol = read(Qfile)
414
- mol.set_calculator(calc)
415
- mol.calc = calc
416
- mol._calc = calc
417
-
418
- # Get the output trajectory file ready
419
- trajfile = os.path.join(output_path, "production.traj")
420
-
421
- # If the masses are given, update the masses
422
- # Note: this must be done BEFORE setting the momenta
423
- if not (isotopeMassesFile is None):
424
- massFile = open(isotopeMassesFile,"r")
425
- newMasses = massFile.readlines()
426
- massFile.close()
427
- if (len(newMasses) != len(mol)): #.masses)):
428
- raise ValueError("Number of masses provided in the isotope mass file does not match the input XYZ")
429
- mol.set_masses([float(i) for i in newMasses])
430
-
431
- # If a rewind-restart file is given, read in the coordinates (Q),
432
- # momenta (P), and energies, for a possible restart
433
- if not (rrQPfile is None):
434
-
435
- print("REWIND-RESTARTING using this file: " + rrQPfile)
436
-
437
- # Look at the last 1500 frames to restart from (but skip the last rrNskip)
438
- rrQPfilehandle = open(rrQPfile)
439
- if (rrNskip <= 0):
440
- rrmols = list(read_xyz(rrQPfilehandle,slice(-1500,None)))
441
- rrNskip = 0
442
- else:
443
- rrmols = list(read_xyz(rrQPfilehandle,slice(-(1500+rrNskip),-rrNskip)))
444
-
445
- rrQPflag = True
446
- Nconsecutivegoodframes = 0
447
- rrmols.reverse() # Go from the most-recent to least-recent
448
- for i,rrmol in enumerate(rrmols):
449
- mol.set_positions(rrmol.get_positions())
450
- mol.set_velocities(rrmol.get_velocities())
451
- mol.set_momenta(rrmol.get_momenta())
452
-
453
- # Compare the original and restarted potential energies
454
- E_original = rrmol.calc.results['energy']
455
- try:
456
- Nconsecutivegoodframes += 1
457
- E_restart = mol.get_potential_energy()
458
- dE = abs(E_original - E_restart) / (units.kcal/units.mol)
459
- print("REWIND-RESTARTING sees that the %d-th to last frame (1-th to last = last frame) has original energy %.3f and restart energy %.3f kcal/mol"
460
- % (rrNskip+i+1, E_original / (units.kcal/units.mol), E_restart / (units.kcal/units.mol)))
461
- except:
462
- Nconsecutivegoodframes = 0
463
- dE = rrQPdEmax * 2
464
- print("REWIND-RESTARTING sees that the %d-th to last frame (1-th to last = last frame) has original energy %.3f and restart energy NaN kcal/mol"
465
- % (rrNskip+i+1, E_original / (units.kcal/units.mol)))
466
-
467
- # If they agree within the threshold, then go ahead with the restart
468
- if (dE < rrQPdEmax):
469
-
470
- # For a smoothed MD simulation, we need a few frames at the start to buffer over
471
- if (Nconsecutivegoodframes < 10):
472
- if (MDtype == "smoothed"): continue
473
-
474
- rrQPflag = False
475
- print("REWIND-RESTARTING accepts using the %d-th to last frame! (1-th to last = last frame)" % (rrNskip+i+1,))
476
- break
477
-
478
- if (rrQPflag):
479
- raise ValueError("REWIND-RESTARTING failed ... no acceptable frames to restart from")
480
-
481
- # If a momenta file is given, read in the momenta
482
- # Read it in as a geometry, and then set it into the molecule
483
- elif not (Pfile is None):
484
- frame = read(Pfile)
485
- p = [atom.position for atom in frame]
486
- mol.set_momenta(p)
487
-
488
- masses=mol.get_masses()
489
- v = [p[i]/masses[i] for i in range(len(p))]
490
- mol.set_velocities(v)
491
-
492
- # If there is no momenta file, then do initial sampling
493
- else:
494
-
495
- Natoms = len(mol)
496
-
497
- # If no atoms are specified to be in the first group,
498
- # assume that this is a unimolecular sampling
499
- if (atomsInFirstGroup is None):
500
- atomsInFirstGroup = range(Natoms)
501
-
502
- atomsInFirstGroup = [int(i)-1 for i in atomsInFirstGroup.split()]
503
-
504
- atomsInSecondGroup = []
505
- for i in range(Natoms):
506
- if (i not in atomsInFirstGroup): atomsInSecondGroup.append(i)
507
-
508
- if ((len(atomsInFirstGroup) > 0) and (len(atomsInSecondGroup) > 0)):
509
- bimolecular_flag = True
510
- if ((ce is None) or (b is None) or (dCM is None)):
511
- raise ValueError("Lacking an argument for bimolecular sampling (collision energy, impact parameter, of center of mass distance)")
512
- else:
513
- bimolecular_flag = False
514
-
515
- print("")
516
- print("GEOMETRY INPUT")
517
- print(" Input geometry file: ", Qfile)
518
- print("Atoms in first group: ", atomsInFirstGroup)
519
- print("Atoms in second group: ", atomsInSecondGroup)
520
- print("SAMPLING INPUT")
521
- print(" Input momenta file: ", Pfile)
522
- if (Pfile is None):
523
- print(" Optimize molecules? ", optimize_flag)
524
- print(" Group A sampling method: ", samplingMethod[0])
525
- print(" Group A vibration: ", vibrationSampling[0])
526
- print(" Group A rotation: ", rotationSampling[0])
527
- print(" Group B sampling method: ", samplingMethod[1])
528
- print(" Group B vibration: ", vibrationSampling[1])
529
- print(" Group B rotation: ", rotationSampling[1])
530
- print(" Impact parameter (A): ", b)
531
- print(" Initial separation (A): ", dCM)
532
- print(" Collsion energy (kcal/mol): ", ce)
533
- else:
534
- print(" Input momenta file: ", Pfile)
535
-
536
- print("##############################################################")
537
- print("")
538
-
539
- # Sample the internal positions and momenta of each of
540
- # the two molecules
541
- sampler = initialSampling(mol,atomsInFirstGroup,optimize=optimize_flag,
542
- optimization_file=os.path.join(output_path, "optimization.traj"),
543
- samplingMethodA=samplingMethod[0],vibrationalSampleA=vibrationSampling[0],rotationalSampleA=rotationSampling[0],
544
- samplingMethodB=samplingMethod[1],vibrationalSampleB=vibrationSampling[1],rotationalSampleB=rotationSampling[1])
545
-
546
- print("Sampling internal degrees of freedom...")
547
- sampler.sampleRelativeQP()
548
-
549
- if (bimolecular_flag):
550
- print("Sampling relative degrees of freedom...")
551
- sampler.sampleAbsoluteQP(ce,dCM=dCM,b=b)
552
-
553
- else:
554
- sampler.centerMolecule(range(Natoms))
555
-
556
- ########################################################################################
557
-
558
- if (MDtype == "regular"):
559
-
560
- MDgen = regularMD(mol,trajfile,dt,Nprint=Nprint)
561
-
562
- elif (MDtype == "pingpong"):
563
-
564
- MDgen = pingpongMD(mol,trajfile,dt,Nprint=Nprint)
565
-
566
- elif (MDtype == "smoothed"):
567
-
568
- # MDgen = smoothedMD(mol,trajfile,dt,Nprint=Nprint,Nrewindsteps=Nrewindsteps,dEmax=dEmax,Edriftmax=Edriftmax)
569
- MDgen = smoothedMD(mol,trajfile,dt,Nprint=Nprint,Nrewindsteps=Nrewindsteps,dEmax=dEmax,Edriftmax=Edriftmax,E0=E0,n_threads=n_threads)
570
-
571
- else:
572
- raise ValueError("MD type '"+MDtype+"' is not valid! Exiting...")
573
-
574
- MDgen.production(Nsteps)
575
-
576
-
577
-
File without changes
File without changes
File without changes
File without changes
File without changes