venuspython 1.0.2__tar.gz → 1.0.3__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.
- {venuspython-1.0.2 → venuspython-1.0.3}/PKG-INFO +1 -1
- {venuspython-1.0.2 → venuspython-1.0.3}/pyproject.toml +7 -7
- venuspython-1.0.3/venuspy/__init__.py +1 -0
- venuspython-1.0.3/venuspy/calc/bagelcalc.py +198 -0
- venuspython-1.0.3/venuspy/calc/chempotpycalc.py +108 -0
- venuspython-1.0.3/venuspy/calc/minisgdmlcalc.py +84 -0
- venuspython-1.0.3/venuspy/calc/mopaccalc.py +154 -0
- venuspython-1.0.3/venuspy/calc/nwchemcalc.py +314 -0
- venuspython-1.0.3/venuspy/calc/nwchemexcalc.py +431 -0
- venuspython-1.0.3/venuspy/calc/original_nwchemexcalc.py +282 -0
- venuspython-1.0.3/venuspy/calc/physnetcalc.py +289 -0
- venuspython-1.0.3/venuspy/calc/psi4calc.py +227 -0
- venuspython-1.0.3/venuspy/calc/qcengineGAMESScalc.py +213 -0
- venuspython-1.0.3/venuspy/calc/xtbcalc.py +358 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspy/initialSampling.py +1 -1
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspython.egg-info/PKG-INFO +1 -1
- venuspython-1.0.3/venuspython.egg-info/SOURCES.txt +23 -0
- venuspython-1.0.2/venuspy/__init__.py +0 -1
- venuspython-1.0.2/venuspython.egg-info/SOURCES.txt +0 -12
- {venuspython-1.0.2 → venuspython-1.0.3}/README.md +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/cli.py +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/setup.cfg +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspy/cli.py +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspy/md.py +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspython.egg-info/dependency_links.txt +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspython.egg-info/entry_points.txt +0 -0
- {venuspython-1.0.2 → venuspython-1.0.3}/venuspython.egg-info/top_level.txt +0 -0
|
@@ -19,15 +19,15 @@ dynamic = ["version", "readme"]
|
|
|
19
19
|
readme = {file = ["README.md"], content-type = "text/markdown"}
|
|
20
20
|
version = {attr = "venuspy.__version__"}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
[tool.setuptools]
|
|
23
|
+
packages = ["venuspy","venuspy.calc"]
|
|
24
24
|
#py_modules = ["venuspy"]
|
|
25
25
|
|
|
26
|
-
[tool.setuptools.packages.find]
|
|
27
|
-
where = ["."] # list of folders that contain the packages (["."] by default)
|
|
28
|
-
include = ["venuspy"] # package names should match these glob patterns (["*"] by default)
|
|
29
|
-
exclude = ["*images*", "*examples*"] # exclude packages matching these glob patterns (empty by default)
|
|
30
|
-
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
|
|
26
|
+
#[tool.setuptools.packages.find]
|
|
27
|
+
#where = ["."] # list of folders that contain the packages (["."] by default)
|
|
28
|
+
#include = ["venuspy"] # package names should match these glob patterns (["*"] by default)
|
|
29
|
+
#exclude = ["*images*", "*examples*"] # exclude packages matching these glob patterns (empty by default)
|
|
30
|
+
#namespaces = false # to disable scanning PEP 420 namespaces (true by default)
|
|
31
31
|
|
|
32
32
|
[project.scripts]
|
|
33
33
|
venuspy-cli = "venuspy:cli"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.3"
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""This module defines an ASE interface to BAGEL.
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from ase import Atoms
|
|
9
|
+
from ase.calculators.calculator import FileIOCalculator, ReadError, Parameters
|
|
10
|
+
from ase.units import kcal, mol, Debye
|
|
11
|
+
|
|
12
|
+
class bagelcalculator(FileIOCalculator):
|
|
13
|
+
# implemented_properties = ['energy', 'forces', 'dipole', 'magmom']
|
|
14
|
+
implemented_properties = ['energy', 'forces', 'dipole']
|
|
15
|
+
|
|
16
|
+
BAGELexe = "/mnt/lustre/koa/koastore/rsun_group/camels/BAGEL_1_AV/BAGEL/bin/BAGEL"
|
|
17
|
+
command = 'mpirun ' + BAGELexe + ' bagel0.json > bagel0.out'
|
|
18
|
+
|
|
19
|
+
discard_results_on_any_change = True
|
|
20
|
+
|
|
21
|
+
def __init__(self, restart=None,
|
|
22
|
+
ignore_bad_restart_file=FileIOCalculator._deprecated,
|
|
23
|
+
label='bagel0', atoms=None, **kwargs):
|
|
24
|
+
"""Construct BAGEL-calculator object.
|
|
25
|
+
|
|
26
|
+
Parameters:
|
|
27
|
+
|
|
28
|
+
label: str
|
|
29
|
+
Prefix for filenames (bagel0.json, bagel0.out, ...)
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
FileIOCalculator.__init__(self, restart, ignore_bad_restart_file,
|
|
35
|
+
label, atoms, **kwargs)
|
|
36
|
+
|
|
37
|
+
# Kazuumi's addition to make a custom input file (must have a 'GEOMETRY HERE' line)
|
|
38
|
+
if ('custominputfile' in kwargs):
|
|
39
|
+
self.custominputfile = kwargs.get('custominputfile',None)
|
|
40
|
+
if not os.path.isfile(self.custominputfile):
|
|
41
|
+
raise ReadError
|
|
42
|
+
|
|
43
|
+
with open(self.custominputfile) as fd:
|
|
44
|
+
lines = fd.readlines()
|
|
45
|
+
|
|
46
|
+
self.pregeometryinput = ''
|
|
47
|
+
self.postgeometryinput = ''
|
|
48
|
+
pregeometry = True
|
|
49
|
+
print("Custom BAGEL input file supplied:")
|
|
50
|
+
for i, line in enumerate(lines):
|
|
51
|
+
print(line,end='')
|
|
52
|
+
if line.find('GEOMETRY HERE') != -1:
|
|
53
|
+
pregeometry = False
|
|
54
|
+
continue
|
|
55
|
+
if (pregeometry):
|
|
56
|
+
self.pregeometryinput += line
|
|
57
|
+
else:
|
|
58
|
+
self.postgeometryinput += line
|
|
59
|
+
|
|
60
|
+
assert pregeometry == False
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
self.custominputfile = None
|
|
64
|
+
|
|
65
|
+
raise ValueError("This version of VENUSpy/BAGEL requires a custominputfile")
|
|
66
|
+
|
|
67
|
+
def write_input(self, atoms, properties=None, system_changes=None):
|
|
68
|
+
FileIOCalculator.write_input(self, atoms, properties, system_changes)
|
|
69
|
+
|
|
70
|
+
s = self.pregeometryinput
|
|
71
|
+
|
|
72
|
+
# Write coordinates:
|
|
73
|
+
Natoms = len(atoms); i = 1; lineend="},\n"
|
|
74
|
+
for xyz, symbol in zip(atoms.positions, atoms.get_chemical_symbols()):
|
|
75
|
+
if (i == Natoms): lineend="}\n"
|
|
76
|
+
s += ' {0} "atom" : "{1}", "xyz" : [ {2}, {3}, {4} ] {5}'.format("{",symbol, *xyz, lineend)
|
|
77
|
+
i += 1
|
|
78
|
+
|
|
79
|
+
# for v, p in zip(atoms.cell, atoms.pbc):
|
|
80
|
+
# if p:
|
|
81
|
+
# s += 'Tv {0} {1} {2}\n'.format(*v)
|
|
82
|
+
|
|
83
|
+
s += self.postgeometryinput
|
|
84
|
+
|
|
85
|
+
with open('bagel0.json', 'w') as fd:
|
|
86
|
+
fd.write(s)
|
|
87
|
+
|
|
88
|
+
def get_index(self, lines, pattern):
|
|
89
|
+
for i, line in enumerate(lines):
|
|
90
|
+
if line.find(pattern) != -1:
|
|
91
|
+
return i
|
|
92
|
+
|
|
93
|
+
def read(self, label='bagel0'):
|
|
94
|
+
FileIOCalculator.read(self, label)
|
|
95
|
+
if not os.path.isfile(self.label + '.out'):
|
|
96
|
+
raise ReadError
|
|
97
|
+
|
|
98
|
+
with open(self.label + '.out') as fd:
|
|
99
|
+
lines = fd.readlines()
|
|
100
|
+
|
|
101
|
+
self.atoms = self.read_atoms_from_file(lines)
|
|
102
|
+
self.read_results()
|
|
103
|
+
|
|
104
|
+
def read_atoms_from_file(self, lines):
|
|
105
|
+
"""Read the Atoms from the output file stored as list of str in lines.
|
|
106
|
+
Parameters:
|
|
107
|
+
|
|
108
|
+
lines: list of str
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
atoms_were_found = False
|
|
112
|
+
for i, line in enumerate(lines):
|
|
113
|
+
if line.find('*** Geometry ***') != -1:
|
|
114
|
+
atoms_were_found = True
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
assert atoms_were_found == True
|
|
118
|
+
|
|
119
|
+
j = 2
|
|
120
|
+
lines1 = lines[i:]
|
|
121
|
+
symbols = []
|
|
122
|
+
positions = []
|
|
123
|
+
while not lines1[j].isspace(): # continue until we hit a blank line
|
|
124
|
+
l = lines1[j].split()
|
|
125
|
+
symbols.append(l[3][1:-2])
|
|
126
|
+
positions.append([float(l[7][:-1]), float(l[8][:-1]), float(l[9])])
|
|
127
|
+
j += 1
|
|
128
|
+
|
|
129
|
+
return Atoms(symbols=symbols, positions=positions)
|
|
130
|
+
|
|
131
|
+
def read_parameters_from_file(self, lines):
|
|
132
|
+
"""Find and return the line that defines a Mopac calculation
|
|
133
|
+
|
|
134
|
+
Parameters:
|
|
135
|
+
|
|
136
|
+
lines: list of str
|
|
137
|
+
"""
|
|
138
|
+
for i, line in enumerate(lines):
|
|
139
|
+
if line.find('CALCULATION DONE:') != -1:
|
|
140
|
+
break
|
|
141
|
+
|
|
142
|
+
lines1 = lines[i:]
|
|
143
|
+
for i, line in enumerate(lines1):
|
|
144
|
+
if line.find('****') != -1:
|
|
145
|
+
return lines1[i + 1]
|
|
146
|
+
|
|
147
|
+
def read_results(self):
|
|
148
|
+
"""Read the results, such as energy, forces, eigenvalues, etc.
|
|
149
|
+
"""
|
|
150
|
+
FileIOCalculator.read(self, self.label)
|
|
151
|
+
if not os.path.isfile(self.label + '.out'):
|
|
152
|
+
raise ReadError
|
|
153
|
+
|
|
154
|
+
with open(self.label + '.out') as fd:
|
|
155
|
+
lines = fd.readlines()
|
|
156
|
+
|
|
157
|
+
# To get the final energies (only for MCSCF right now)
|
|
158
|
+
# awk 'BEGIN {Nstate=0} /FCI iteration/ {flag=1;Niter=0} /ci vector/ {if(flag==1){print $0, E};flag=0} {if(flag==1 && $1 == Niter && $2 == Nstate){E=$(NF-2);Niter+=1}}' casscf.log | tail
|
|
159
|
+
|
|
160
|
+
Natoms = len(self.atoms)
|
|
161
|
+
|
|
162
|
+
BAGEL_FCI_iteration_flag = False
|
|
163
|
+
for i, line in enumerate(lines):
|
|
164
|
+
|
|
165
|
+
# Print one copy of the output to the screen
|
|
166
|
+
print(line,end="")
|
|
167
|
+
|
|
168
|
+
if line.find('FCI iteration') != -1:
|
|
169
|
+
BAGEL_FCI_iteration_flag = True
|
|
170
|
+
Niter = "0"
|
|
171
|
+
Nstate = "0" # Assume we are looking for the ground state (state 0)
|
|
172
|
+
|
|
173
|
+
elif line.find('ci vector') != -1:
|
|
174
|
+
BAGEL_FCI_iteration_flag = False
|
|
175
|
+
# print("Energy: " + str(self.results['energy']) + " " + line,end='')
|
|
176
|
+
|
|
177
|
+
elif (BAGEL_FCI_iteration_flag):
|
|
178
|
+
BAGEL_fields = line.split()
|
|
179
|
+
|
|
180
|
+
if (len(BAGEL_fields) >= 5 and BAGEL_fields[0] == Niter and BAGEL_fields[1] == Nstate):
|
|
181
|
+
Niter = str(int(Niter) + 1)
|
|
182
|
+
self.results['energy'] = float(BAGEL_fields[-3]) # * kcal / mol
|
|
183
|
+
|
|
184
|
+
elif line.find('Nuclear energy gradient') != -1:
|
|
185
|
+
forces = [-float(line.split()[1])
|
|
186
|
+
for j, line in enumerate(lines[i+2:i+2 + 4 * Natoms]) if j%4>0 ]
|
|
187
|
+
self.results['forces'] = np.array(
|
|
188
|
+
forces).reshape((-1, 3)) # * kcal / mol
|
|
189
|
+
# print("Forces: ", self.results['forces'])
|
|
190
|
+
|
|
191
|
+
elif line.find('Permanent dipole moment') != -1:
|
|
192
|
+
if line.find('Permanent dipole moment: Unrelaxed') != -1: continue
|
|
193
|
+
|
|
194
|
+
self.results['dipole'] = np.array(
|
|
195
|
+
[float(astring[:-1]) for astring in lines[i+1].split()[1:4]]) * Debye
|
|
196
|
+
# print("Dipole: ", self.results['dipole'])
|
|
197
|
+
|
|
198
|
+
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
import chempotpy
|
|
6
|
+
|
|
7
|
+
from ase.calculators.calculator import Calculator
|
|
8
|
+
from ase.units import eV, kcal, mol
|
|
9
|
+
|
|
10
|
+
class chempotpyCalculator(Calculator):
|
|
11
|
+
|
|
12
|
+
implemented_properties = ['energy', 'forces']
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
model,
|
|
17
|
+
E_to_eV=eV, # kcal / mol,
|
|
18
|
+
F_to_eV_Ang=eV, # kcal / mol,
|
|
19
|
+
n_threads=None,
|
|
20
|
+
*args,
|
|
21
|
+
**kwargs
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
ASE calculator for a chempotpy potential.
|
|
25
|
+
|
|
26
|
+
A calculator takes atomic numbers and atomic positions from an Atoms object and calculates the energy and forces.
|
|
27
|
+
|
|
28
|
+
Note
|
|
29
|
+
----
|
|
30
|
+
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.
|
|
31
|
+
Here is how to find them: `ASE units <https://wiki.fysik.dtu.dk/ase/ase/units.html>`_.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
model : :obj:`chempotpy model`
|
|
36
|
+
A chempotpy model file
|
|
37
|
+
E_to_eV : float, optional
|
|
38
|
+
Conversion factor from whatever energy unit is used by the model to eV. By default this parameter is set to convert from kcal/mol.
|
|
39
|
+
F_to_eV_Ang : float, optional
|
|
40
|
+
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)
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
super(chempotpyCalculator, self).__init__(*args, **kwargs)
|
|
44
|
+
|
|
45
|
+
self.log = logging.getLogger(__name__)
|
|
46
|
+
|
|
47
|
+
modelargs = model.split()
|
|
48
|
+
|
|
49
|
+
# Figure out whether the "model" input is a file or a one-liner description
|
|
50
|
+
if (len(modelargs) == 1): # This is a file
|
|
51
|
+
with open(modelargs[0]) as f:
|
|
52
|
+
modelargs = f.readlines()[0]
|
|
53
|
+
|
|
54
|
+
self.system = modelargs[2]
|
|
55
|
+
self.modelname = modelargs[3]
|
|
56
|
+
|
|
57
|
+
# Figure out whether this is multistate or not
|
|
58
|
+
if (len(modelargs) > 4):
|
|
59
|
+
self.multistate = True
|
|
60
|
+
self.state = int(modelargs[4])
|
|
61
|
+
else:
|
|
62
|
+
self.multistate = False
|
|
63
|
+
|
|
64
|
+
self.log.warning(
|
|
65
|
+
'Please remember to specify the proper conversion factors, if your model does not use \'kcal/mol\' and \'Ang\' as units.'
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# From the chempotpy documentation:
|
|
69
|
+
# The input to ChemPotPy is ALWAYS Cartesian coordinates in angstroms.
|
|
70
|
+
# The output units are ALWAYS potential energies in eV, gradients in
|
|
71
|
+
# eV/angstrom, and nonadiabatic coupling vectors in 1/angstrom.
|
|
72
|
+
|
|
73
|
+
# Converts energy from the unit used by the sGDML model to eV.
|
|
74
|
+
self.E_to_eV = E_to_eV
|
|
75
|
+
|
|
76
|
+
# Converts length from eV to unit used in sGDML model.
|
|
77
|
+
self.Ang_to_R = F_to_eV_Ang / E_to_eV
|
|
78
|
+
|
|
79
|
+
# Converts force from the unit used by the sGDML model to eV/Ang.
|
|
80
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
81
|
+
|
|
82
|
+
def calculate(self, atoms=None, *args, **kwargs):
|
|
83
|
+
|
|
84
|
+
super(chempotpyCalculator, self).calculate(atoms, *args, **kwargs)
|
|
85
|
+
|
|
86
|
+
# convert model units to ASE default units
|
|
87
|
+
r = atoms.get_positions() * self.Ang_to_R
|
|
88
|
+
geom = []; i = 0
|
|
89
|
+
for atom in atoms:
|
|
90
|
+
geom.append([atom.symbol, r[i][0], r[i][1], r[i][2]]); i+=1
|
|
91
|
+
|
|
92
|
+
e, f, nac = chempotpy.pgd(self.system,self.modelname,geom)
|
|
93
|
+
|
|
94
|
+
# convert model units to ASE default units (eV and Ang)
|
|
95
|
+
if (self.multistate):
|
|
96
|
+
e = e[self.state] * self.E_to_eV
|
|
97
|
+
f = -f[self.state] * self.F_to_eV_Ang
|
|
98
|
+
else:
|
|
99
|
+
e = e * self.E_to_eV
|
|
100
|
+
f = -f * self.F_to_eV_Ang
|
|
101
|
+
|
|
102
|
+
self.results = {'energy': e, 'forces': f.reshape(-1, 3)}
|
|
103
|
+
|
|
104
|
+
def get_forces(self, atoms=None, force_consistent=False):
|
|
105
|
+
forces = self.get_property('forces', atoms)
|
|
106
|
+
return forces
|
|
107
|
+
|
|
108
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
import sgdml
|
|
6
|
+
from sgdml.train import GDMLTrain
|
|
7
|
+
from sgdml.predict import GDMLPredict
|
|
8
|
+
from sgdml.intf.ase_calc import SGDMLCalculator
|
|
9
|
+
|
|
10
|
+
from ase.calculators.calculator import Calculator
|
|
11
|
+
from ase.units import kcal, mol
|
|
12
|
+
|
|
13
|
+
class miniSGDMLCalculator(Calculator):
|
|
14
|
+
|
|
15
|
+
implemented_properties = ['energy', 'forces']
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
model,
|
|
20
|
+
E_to_eV=kcal / mol,
|
|
21
|
+
F_to_eV_Ang=kcal / mol,
|
|
22
|
+
n_threads=None,
|
|
23
|
+
use_torch=False,
|
|
24
|
+
*args,
|
|
25
|
+
**kwargs
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
ASE calculator for the sGDML force field.
|
|
29
|
+
|
|
30
|
+
A calculator takes atomic numbers and atomic positions from an Atoms object and calculates the energy and forces.
|
|
31
|
+
|
|
32
|
+
Note
|
|
33
|
+
----
|
|
34
|
+
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.
|
|
35
|
+
Here is how to find them: `ASE units <https://wiki.fysik.dtu.dk/ase/ase/units.html>`_.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
model : :obj:`sGDML model`
|
|
40
|
+
A sGDML model file
|
|
41
|
+
E_to_eV : float, optional
|
|
42
|
+
Conversion factor from whatever energy unit is used by the model to eV. By default this parameter is set to convert from kcal/mol.
|
|
43
|
+
F_to_eV_Ang : float, optional
|
|
44
|
+
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)
|
|
45
|
+
use_torch : boolean, optional
|
|
46
|
+
Use PyTorch to calculate predictions
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
super(miniSGDMLCalculator, self).__init__(*args, **kwargs)
|
|
50
|
+
|
|
51
|
+
self.log = logging.getLogger(__name__)
|
|
52
|
+
|
|
53
|
+
# self.gdml_predict = GDMLPredict(model, use_torch=use_torch)
|
|
54
|
+
self.gdml_predict = GDMLPredict(model, num_workers=n_threads, use_torch=use_torch)
|
|
55
|
+
self.gdml_predict.prepare_parallel(n_bulk=1)
|
|
56
|
+
|
|
57
|
+
self.log.warning(
|
|
58
|
+
'Please remember to specify the proper conversion factors, if your model does not use \'kcal/mol\' and \'Ang\' as units.'
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Converts energy from the unit used by the sGDML model to eV.
|
|
62
|
+
self.E_to_eV = E_to_eV
|
|
63
|
+
|
|
64
|
+
# Converts length from eV to unit used in sGDML model.
|
|
65
|
+
self.Ang_to_R = F_to_eV_Ang / E_to_eV
|
|
66
|
+
|
|
67
|
+
# Converts force from the unit used by the sGDML model to eV/Ang.
|
|
68
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
69
|
+
|
|
70
|
+
def calculate(self, atoms=None, *args, **kwargs):
|
|
71
|
+
|
|
72
|
+
super(miniSGDMLCalculator, self).calculate(atoms, *args, **kwargs)
|
|
73
|
+
|
|
74
|
+
# convert model units to ASE default units
|
|
75
|
+
r = np.array(atoms.get_positions()) * self.Ang_to_R
|
|
76
|
+
|
|
77
|
+
e, f = self.gdml_predict.predict(r.ravel())
|
|
78
|
+
|
|
79
|
+
# convert model units to ASE default units (eV and Ang)
|
|
80
|
+
e *= self.E_to_eV
|
|
81
|
+
f *= self.F_to_eV_Ang
|
|
82
|
+
|
|
83
|
+
self.results = {'energy': e, 'forces': f.reshape(-1, 3)}
|
|
84
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
from ase.calculators.mopac import MOPAC
|
|
8
|
+
|
|
9
|
+
# For debugging:
|
|
10
|
+
import os.path
|
|
11
|
+
|
|
12
|
+
class mopaccalculator(Calculator):
|
|
13
|
+
|
|
14
|
+
implemented_properties = ['energy', 'forces']
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
input_path,
|
|
19
|
+
output_path=None,
|
|
20
|
+
E_to_eV=Ha,
|
|
21
|
+
F_to_eV_Ang=Ha/Bohr,
|
|
22
|
+
use_torch=False,
|
|
23
|
+
*args,
|
|
24
|
+
**kwargs
|
|
25
|
+
):
|
|
26
|
+
"""
|
|
27
|
+
ASE calculator for the MOPAC ab initio module
|
|
28
|
+
|
|
29
|
+
A calculator takes atomic numbers and atomic positions from an Atoms object and calculates the energy and forces.
|
|
30
|
+
|
|
31
|
+
Note
|
|
32
|
+
----
|
|
33
|
+
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.
|
|
34
|
+
Here is how to find them: `ASE units <https://wiki.fysik.dtu.dk/ase/ase/units.html>`_.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
input_path : :obj:`str`
|
|
39
|
+
Path to a NWChem input file
|
|
40
|
+
E_to_eV : float, optional
|
|
41
|
+
Conversion factor from whatever energy unit is used by the model to eV. By default this parameter is set to convert from kcal/mol.
|
|
42
|
+
F_to_eV_Ang : float, optional
|
|
43
|
+
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)
|
|
44
|
+
use_torch : boolean, optional
|
|
45
|
+
Use PyTorch to calculate predictions
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
super(mopaccalculator, self).__init__(*args, **kwargs)
|
|
49
|
+
|
|
50
|
+
# Some suggested default values (for MD)
|
|
51
|
+
# self.maxiter = 5000
|
|
52
|
+
# self.d_convergence = 1.0e-8
|
|
53
|
+
# self.e_convergence = 1.0e-8
|
|
54
|
+
# self.freeze_core = 1
|
|
55
|
+
|
|
56
|
+
# Default values for the input
|
|
57
|
+
self.method = 'PM7' # LevelOfTheory
|
|
58
|
+
self.charge = 0
|
|
59
|
+
self.multiplicity = 2 # 2s+1
|
|
60
|
+
self.save_movecs_interval = None
|
|
61
|
+
self.custominput = None
|
|
62
|
+
|
|
63
|
+
# Some input values that are currently not set up (handled differently by QCEngine)
|
|
64
|
+
self.memory = 1500 # In MB
|
|
65
|
+
self.scratchdir = "/tmp"
|
|
66
|
+
|
|
67
|
+
# Read in the input
|
|
68
|
+
with open(input_path, 'r') as f:
|
|
69
|
+
for line in f:
|
|
70
|
+
strippedline=" ".join(line.split())
|
|
71
|
+
entries = strippedline.split(" ")
|
|
72
|
+
if (entries[0] == "memory"): self.memory = int(entries[1])
|
|
73
|
+
if (entries[0] == "scratchdir"): self.scratchdir = str(entries[1])
|
|
74
|
+
elif (entries[0] == "method"): self.method = str(entries[1])
|
|
75
|
+
elif (entries[0] == "mulliken"): pass
|
|
76
|
+
elif (entries[0] == "charge"): self.charge = int(entries[1])
|
|
77
|
+
elif (entries[0] == "multiplicity"): self.multiplicity = int(entries[1])
|
|
78
|
+
elif (entries[0] == "custominput"): self.custominput = " ".join(entries[1:])
|
|
79
|
+
elif (entries[0] == "maxiter"):
|
|
80
|
+
self.maxiter = int(entries[1])
|
|
81
|
+
|
|
82
|
+
else:
|
|
83
|
+
print("Ignoring keyword line (nothing will be added to the NWChem input file) with entries: ", entries)
|
|
84
|
+
|
|
85
|
+
# Get the calculator, the spin, and the charge ready
|
|
86
|
+
self.spinarray = None
|
|
87
|
+
self.chargearray = None
|
|
88
|
+
self.mopaccalc = MOPAC(label='.tmp',task='1SCF GRADIENTS')
|
|
89
|
+
self.mopaccalc.parameters['relscf'] = 0.0001 # default is 0.0001
|
|
90
|
+
# self.mopaccalc.parameters['relscf'] = 0.00001 # default is 0.0001
|
|
91
|
+
|
|
92
|
+
if (not (self.custominput is None)):
|
|
93
|
+
self.mopaccalc = MOPAC(label='.tmp',task='1SCF GRADIENTS',custominput="AM1 VECTORS 1SCF GRADIENTS GEO-OK C.I.=6 SINGLET"); self.multiplicity = 1 # temporary change
|
|
94
|
+
|
|
95
|
+
# Converts energy from the unit used by the ab initio method to eV.
|
|
96
|
+
self.E_to_eV = E_to_eV
|
|
97
|
+
|
|
98
|
+
# Converts length from the unit used in the ab initio method to Ang.
|
|
99
|
+
self.Ang_to_R = F_to_eV_Ang / E_to_eV
|
|
100
|
+
|
|
101
|
+
# Converts force from the unit used by the ab initio method to eV/Ang.
|
|
102
|
+
self.F_to_eV_Ang = F_to_eV_Ang
|
|
103
|
+
|
|
104
|
+
print("Summary of MOPAC ab initio input file")
|
|
105
|
+
print(" Method:", self.method)
|
|
106
|
+
|
|
107
|
+
def calculate(self, atoms=None, *args, **kwargs):
|
|
108
|
+
|
|
109
|
+
# Set the total spin + charge for the MOPAC calculation
|
|
110
|
+
# by setting initial local spins + charges
|
|
111
|
+
if (self.spinarray is None):
|
|
112
|
+
dum1 = np.array([0 for i in atoms])
|
|
113
|
+
self.spinarray = dum1.copy()
|
|
114
|
+
self.spinarray[0] = self.multiplicity - 1
|
|
115
|
+
self.chargearray = dum1.copy()
|
|
116
|
+
self.chargearray[0] = self.charge
|
|
117
|
+
|
|
118
|
+
atoms.set_initial_magnetic_moments(self.spinarray)
|
|
119
|
+
atoms.set_initial_charges(self.chargearray)
|
|
120
|
+
|
|
121
|
+
super(mopaccalculator, self).calculate(atoms, *args, **kwargs)
|
|
122
|
+
|
|
123
|
+
f = self.mopaccalc.get_forces(atoms=atoms)
|
|
124
|
+
e = self.mopaccalc.get_final_heat_of_formation()
|
|
125
|
+
|
|
126
|
+
# Print the NWChem output to stdout
|
|
127
|
+
with open('.tmp.out', 'r') as afile:
|
|
128
|
+
print(afile.read())
|
|
129
|
+
|
|
130
|
+
# Make sure that the gradient was correctly read in
|
|
131
|
+
assert len(atoms) == len(f)
|
|
132
|
+
|
|
133
|
+
# Convert model units to ASE default units (eV and Ang)
|
|
134
|
+
e *= self.E_to_eV
|
|
135
|
+
f *= self.F_to_eV_Ang
|
|
136
|
+
|
|
137
|
+
f = f.reshape(-1, 3)
|
|
138
|
+
Natoms = len(atoms)
|
|
139
|
+
print("")
|
|
140
|
+
print("MOPAC flag 1")
|
|
141
|
+
print(Natoms)
|
|
142
|
+
print("Energy: ", e)
|
|
143
|
+
#for anAtom in atoms:
|
|
144
|
+
for i in range(Natoms):
|
|
145
|
+
anAtom = atoms[i]
|
|
146
|
+
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]))
|
|
147
|
+
print("")
|
|
148
|
+
|
|
149
|
+
self.results = {'energy': e, 'forces': f}
|
|
150
|
+
|
|
151
|
+
def get_forces(self, atoms=None, force_consistent=False):
|
|
152
|
+
forces = self.get_property('forces', atoms)
|
|
153
|
+
return forces
|
|
154
|
+
|