lammpsparser 0.0.1__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.
- lammpsparser/__init__.py +38 -0
- lammpsparser/_version.py +34 -0
- lammpsparser/compatibility/__init__.py +0 -0
- lammpsparser/compatibility/calculate.py +484 -0
- lammpsparser/compatibility/constraints.py +106 -0
- lammpsparser/compatibility/file.py +285 -0
- lammpsparser/compatibility/structure.py +336 -0
- lammpsparser/output.py +340 -0
- lammpsparser/output_raw.py +251 -0
- lammpsparser/potential.py +380 -0
- lammpsparser/structure.py +536 -0
- lammpsparser/units.py +246 -0
- lammpsparser-0.0.1.dist-info/METADATA +146 -0
- lammpsparser-0.0.1.dist-info/RECORD +16 -0
- lammpsparser-0.0.1.dist-info/WHEEL +4 -0
- lammpsparser-0.0.1.dist-info/licenses/LICENSE +29 -0
lammpsparser/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import lammpsparser._version
|
|
2
|
+
from lammpsparser.compatibility.calculate import calc_md, calc_minimize, calc_static
|
|
3
|
+
from lammpsparser.compatibility.file import (
|
|
4
|
+
lammps_file_initialization,
|
|
5
|
+
lammps_file_interface_function,
|
|
6
|
+
)
|
|
7
|
+
from lammpsparser.output import parse_lammps_output as parse_lammps_output_files
|
|
8
|
+
from lammpsparser.potential import (
|
|
9
|
+
get_potential_by_name,
|
|
10
|
+
get_potential_dataframe,
|
|
11
|
+
validate_potential_dataframe,
|
|
12
|
+
)
|
|
13
|
+
from lammpsparser.structure import write_lammps_datafile as write_lammps_structure
|
|
14
|
+
|
|
15
|
+
DUMP_COMMANDS = [
|
|
16
|
+
"dump 1 all custom 100 dump.out id type xsu ysu zsu fx fy fz vx vy vz\n",
|
|
17
|
+
'dump_modify 1 sort id format line "%d %d %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g"\n',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
THERMO_COMMANDS = [
|
|
21
|
+
"thermo_style custom step temp pe etotal pxx pxy pxz pyy pyz pzz vol\n",
|
|
22
|
+
"thermo_modify format float %20.15g\n",
|
|
23
|
+
"thermo 100\n",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
__version__ = lammpsparser._version.__version__
|
|
27
|
+
__all__ = [
|
|
28
|
+
"calc_md",
|
|
29
|
+
"calc_minimize",
|
|
30
|
+
"calc_static",
|
|
31
|
+
"get_potential_by_name",
|
|
32
|
+
"get_potential_dataframe",
|
|
33
|
+
"lammps_file_initialization",
|
|
34
|
+
"lammps_file_interface_function",
|
|
35
|
+
"parse_lammps_output_files",
|
|
36
|
+
"validate_potential_dataframe",
|
|
37
|
+
"write_lammps_structure",
|
|
38
|
+
]
|
lammpsparser/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.0.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
|
File without changes
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from ase.atoms import Atoms
|
|
5
|
+
|
|
6
|
+
from lammpsparser.structure import UnfoldingPrism
|
|
7
|
+
from lammpsparser.units import LAMMPS_UNIT_CONVERSIONS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def calc_md(
|
|
11
|
+
temperature=None,
|
|
12
|
+
pressure=None,
|
|
13
|
+
time_step=1.0,
|
|
14
|
+
n_print=100,
|
|
15
|
+
temperature_damping_timescale=100.0,
|
|
16
|
+
pressure_damping_timescale=1000.0,
|
|
17
|
+
seed=80996,
|
|
18
|
+
tloop=None,
|
|
19
|
+
initial_temperature=None,
|
|
20
|
+
langevin=False,
|
|
21
|
+
delta_temp=None,
|
|
22
|
+
delta_press=None,
|
|
23
|
+
rotation_matrix=None,
|
|
24
|
+
units="metal",
|
|
25
|
+
):
|
|
26
|
+
"""
|
|
27
|
+
Set an MD calculation within LAMMPS. Nosé Hoover is used by default.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
temperature (None/float/list): Target temperature value(-s). If set to None, an NVE
|
|
31
|
+
calculation is performed. It is required when the pressure is set or langevin is set
|
|
32
|
+
It can be a list of temperature values, containing the initial target temperature and
|
|
33
|
+
the final target temperature (in between the target value is varied linearly).
|
|
34
|
+
pressure (None/float/numpy.ndarray/list): Target pressure. If set to None, an NVE or an
|
|
35
|
+
NVT calculation is performed. If set to a scalar, the shear of the cell and the
|
|
36
|
+
ratio of the x, y, and z components is kept constant, while an isotropic, hydrostatic
|
|
37
|
+
pressure is applied. A list of up to length 6 can be given to specify xx, yy, zz, xy,
|
|
38
|
+
xz, and yz components of the pressure tensor, respectively. These values can mix
|
|
39
|
+
floats and `None` to allow only certain degrees of cell freedom to change. (Default
|
|
40
|
+
is None, run isochorically.)
|
|
41
|
+
n_ionic_steps (int): Number of ionic steps
|
|
42
|
+
time_step (float): Step size in fs between two steps.
|
|
43
|
+
n_print (int): Print frequency
|
|
44
|
+
temperature_damping_timescale (float): The time associated with the thermostat adjusting
|
|
45
|
+
the temperature. (In fs. After rescaling to appropriate time units, is equivalent to
|
|
46
|
+
Lammps' `Tdamp`.)
|
|
47
|
+
pressure_damping_timescale (float): The time associated with the barostat adjusting the
|
|
48
|
+
temperature. (In fs. After rescaling to appropriate time units, is equivalent to
|
|
49
|
+
Lammps' `Pdamp`.)
|
|
50
|
+
seed (int): Seed for the random number generation used for the intiial velocity creation
|
|
51
|
+
and langevin dynamics - otherwise ignored. If not specified, the seed is created via
|
|
52
|
+
job name
|
|
53
|
+
tloop:
|
|
54
|
+
initial_temperature (None/float): Initial temperature according to which the initial
|
|
55
|
+
velocity field is created. If None, the initial temperature will be twice the target
|
|
56
|
+
temperature (which would go immediately down to the target temperature as described
|
|
57
|
+
in equipartition theorem). If 0, the velocity field is not initialized (in which case
|
|
58
|
+
the initial velocity given in structure will be used). If any other number is given,
|
|
59
|
+
this value is going to be used for the initial temperature.
|
|
60
|
+
langevin (bool): (True or False) Activate Langevin dynamics
|
|
61
|
+
delta_temp (float): Thermostat timescale, but in your Lammps time units, whatever those
|
|
62
|
+
are. (DEPRECATED.)
|
|
63
|
+
delta_press (float): Barostat timescale, but in your Lammps time units, whatever those
|
|
64
|
+
are. (DEPRECATED.)
|
|
65
|
+
job_name (str): Job name of the job to generate a unique random seed.
|
|
66
|
+
rotation_matrix (numpy.ndarray): The rotation matrix from the pyiron to Lammps coordinate
|
|
67
|
+
frame.
|
|
68
|
+
"""
|
|
69
|
+
if units not in LAMMPS_UNIT_CONVERSIONS.keys():
|
|
70
|
+
raise NotImplementedError
|
|
71
|
+
time_units = LAMMPS_UNIT_CONVERSIONS[units]["time"]
|
|
72
|
+
temperature_units = LAMMPS_UNIT_CONVERSIONS[units]["temperature"]
|
|
73
|
+
|
|
74
|
+
# Transform time
|
|
75
|
+
if time_step is not None:
|
|
76
|
+
time_step *= time_units
|
|
77
|
+
|
|
78
|
+
# Transform thermostat strength (time)
|
|
79
|
+
if delta_temp is not None:
|
|
80
|
+
warnings.warn(
|
|
81
|
+
"WARNING: `delta_temp` is deprecated, please use `temperature_damping_timescale`."
|
|
82
|
+
)
|
|
83
|
+
temperature_damping_timescale = delta_temp
|
|
84
|
+
else:
|
|
85
|
+
temperature_damping_timescale *= time_units
|
|
86
|
+
|
|
87
|
+
# Transform barostat strength (time)
|
|
88
|
+
if delta_press is not None:
|
|
89
|
+
warnings.warn(
|
|
90
|
+
"WARNING: `delta_press` is deprecated, please use `pressure_damping_timescale`."
|
|
91
|
+
)
|
|
92
|
+
pressure_damping_timescale = delta_press
|
|
93
|
+
else:
|
|
94
|
+
pressure_damping_timescale *= time_units
|
|
95
|
+
|
|
96
|
+
# Transform temperature
|
|
97
|
+
if temperature is not None:
|
|
98
|
+
temperature = np.array([temperature], dtype=float).flatten()
|
|
99
|
+
if len(temperature) == 1:
|
|
100
|
+
temperature = np.array(2 * temperature.tolist())
|
|
101
|
+
elif len(temperature) != 2:
|
|
102
|
+
raise ValueError(
|
|
103
|
+
"At most two temperatures can be provided "
|
|
104
|
+
"(for a linearly ramping target temperature), "
|
|
105
|
+
"but got {}".format(len(temperature))
|
|
106
|
+
)
|
|
107
|
+
temperature *= temperature_units
|
|
108
|
+
|
|
109
|
+
# Apply initial overheating (default uses the theorem of equipartition of energy between KE and PE)
|
|
110
|
+
if initial_temperature is None and temperature is not None:
|
|
111
|
+
initial_temperature = 2 * temperature[0]
|
|
112
|
+
|
|
113
|
+
if seed <= 0:
|
|
114
|
+
raise ValueError("Seed must be a positive integer larger than 0")
|
|
115
|
+
|
|
116
|
+
thermo_str = ""
|
|
117
|
+
# Set thermodynamic ensemble
|
|
118
|
+
if pressure is not None: # NPT
|
|
119
|
+
if temperature is None or temperature.min() <= 0:
|
|
120
|
+
raise ValueError(
|
|
121
|
+
"Target temperature for fix nvt/npt/nph cannot be 0 or negative"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
force_skewed = False
|
|
125
|
+
pressure = _pressure_to_lammps(
|
|
126
|
+
pressure=pressure, rotation_matrix=rotation_matrix, units=units
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
if np.isscalar(pressure):
|
|
130
|
+
pressure_string = " iso {0} {0} {1}".format(
|
|
131
|
+
pressure, pressure_damping_timescale
|
|
132
|
+
)
|
|
133
|
+
else:
|
|
134
|
+
pressure_string = ""
|
|
135
|
+
for ii, (coord, value) in enumerate(
|
|
136
|
+
zip(["x", "y", "z", "xy", "xz", "yz"], pressure)
|
|
137
|
+
):
|
|
138
|
+
if value is not None:
|
|
139
|
+
pressure_string += " {0} {1} {1} {2}".format(
|
|
140
|
+
coord, value, pressure_damping_timescale
|
|
141
|
+
)
|
|
142
|
+
if ii > 2:
|
|
143
|
+
force_skewed = True
|
|
144
|
+
|
|
145
|
+
if langevin: # NPT(Langevin)
|
|
146
|
+
fix_ensemble_str = "fix ensemble all nph" + pressure_string
|
|
147
|
+
thermo_str = "fix langevin all langevin {0} {1} {2} {3} zero yes".format(
|
|
148
|
+
str(temperature[0]),
|
|
149
|
+
str(temperature[1]),
|
|
150
|
+
str(temperature_damping_timescale),
|
|
151
|
+
str(seed),
|
|
152
|
+
)
|
|
153
|
+
else: # NPT(Nose-Hoover)
|
|
154
|
+
fix_ensemble_str = "fix ensemble all npt temp {0} {1} {2}".format(
|
|
155
|
+
str(temperature[0]),
|
|
156
|
+
str(temperature[1]),
|
|
157
|
+
str(temperature_damping_timescale),
|
|
158
|
+
)
|
|
159
|
+
fix_ensemble_str += pressure_string
|
|
160
|
+
elif temperature is not None: # NVT
|
|
161
|
+
if temperature.min() <= 0:
|
|
162
|
+
raise ValueError(
|
|
163
|
+
"Target temperature for fix nvt/npt/nph cannot be 0 or negative"
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if langevin: # NVT(Langevin)
|
|
167
|
+
fix_ensemble_str = "fix ensemble all nve"
|
|
168
|
+
thermo_str = "fix langevin all langevin {0} {1} {2} {3} zero yes".format(
|
|
169
|
+
str(temperature[0]),
|
|
170
|
+
str(temperature[1]),
|
|
171
|
+
str(temperature_damping_timescale),
|
|
172
|
+
str(seed),
|
|
173
|
+
)
|
|
174
|
+
else: # NVT(Nose-Hoover)
|
|
175
|
+
fix_ensemble_str = "fix ensemble all nvt temp {0} {1} {2}".format(
|
|
176
|
+
str(temperature[0]),
|
|
177
|
+
str(temperature[1]),
|
|
178
|
+
str(temperature_damping_timescale),
|
|
179
|
+
)
|
|
180
|
+
else: # NVE
|
|
181
|
+
if langevin:
|
|
182
|
+
warnings.warn("Temperature not set; Langevin ignored.")
|
|
183
|
+
fix_ensemble_str = "fix ensemble all nve"
|
|
184
|
+
|
|
185
|
+
if tloop is not None:
|
|
186
|
+
fix_ensemble_str += " tloop " + str(tloop)
|
|
187
|
+
|
|
188
|
+
line_lst = [fix_ensemble_str]
|
|
189
|
+
if thermo_str != "":
|
|
190
|
+
line_lst.append(thermo_str)
|
|
191
|
+
|
|
192
|
+
line_lst.append("variable thermotime equal {} ".format(n_print))
|
|
193
|
+
line_lst.append("timestep {}".format(time_step))
|
|
194
|
+
if initial_temperature is not None and initial_temperature > 0:
|
|
195
|
+
line_lst.append(
|
|
196
|
+
_set_initial_velocity(
|
|
197
|
+
temperature=initial_temperature,
|
|
198
|
+
seed=seed,
|
|
199
|
+
gaussian=True,
|
|
200
|
+
append_value=False,
|
|
201
|
+
zero_lin_momentum=True,
|
|
202
|
+
zero_rot_momentum=True,
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
line_lst += _get_thermo()
|
|
206
|
+
return line_lst
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def calc_minimize(
|
|
210
|
+
structure: Atoms,
|
|
211
|
+
ionic_energy_tolerance=0.0,
|
|
212
|
+
ionic_force_tolerance=1e-4,
|
|
213
|
+
max_iter=100000,
|
|
214
|
+
pressure=None,
|
|
215
|
+
n_print=100,
|
|
216
|
+
style="cg",
|
|
217
|
+
rotation_matrix=None,
|
|
218
|
+
units="metal",
|
|
219
|
+
):
|
|
220
|
+
"""
|
|
221
|
+
Sets parameters required for minimization.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
ionic_energy_tolerance (float): If the magnitude of difference between energies of two consecutive steps is
|
|
225
|
+
lower than or equal to `ionic_energy_tolerance`, the minimisation terminates. (Default is 0.0 eV.)
|
|
226
|
+
ionic_force_tolerance (float): If the magnitude of the global force vector at a step is lower than or equal
|
|
227
|
+
to `ionic_force_tolerance`, the minimisation terminates. (Default is 1e-4 eV/angstrom.)
|
|
228
|
+
e_tol (float): Same as ionic_energy_tolerance (deprecated)
|
|
229
|
+
f_tol (float): Same as ionic_force_tolerance (deprecated)
|
|
230
|
+
max_iter (int): Maximum number of minimisation steps to carry out. If the minimisation converges before
|
|
231
|
+
`max_iter` steps, terminate at the converged step. If the minimisation does not converge up to
|
|
232
|
+
`max_iter` steps, terminate at the `max_iter` step. (Default is 100000.)
|
|
233
|
+
pressure (None/float/numpy.ndarray/list): Target pressure. If set to None, an isochoric (constant V)
|
|
234
|
+
calculation is performed. If set to a scalar, the shear of the cell and the ratio of the x, y, and
|
|
235
|
+
z components is kept constant, while an isotropic, hydrostatic pressure is applied. A list of up to
|
|
236
|
+
length 6 can be given to specify xx, yy, zz, xy, xz, and yz components of the pressure tensor,
|
|
237
|
+
respectively. These values can mix floats and `None` to allow only certain degrees of cell freedom
|
|
238
|
+
to change. (Default is None, run isochorically.)
|
|
239
|
+
n_print (int): Write (dump or print) to the output file every n steps (Default: 100)
|
|
240
|
+
style ('cg'/'sd'/other values from Lammps docs): The style of the numeric minimization, either conjugate
|
|
241
|
+
gradient, steepest descent, or other keys permissible from the Lammps docs on 'min_style'. (Default
|
|
242
|
+
is 'cg' -- conjugate gradient.)
|
|
243
|
+
rotation_matrix (numpy.ndarray): The rotation matrix from the pyiron to Lammps coordinate frame.
|
|
244
|
+
"""
|
|
245
|
+
# This docstring is a source for the calc_minimize method in pyiron_atomistics.lammps.base.LammpsBase.calc_minimize and
|
|
246
|
+
# pyiron_atomistics.lammps.interactive.LammpsInteractive.calc_minimize -- Please ensure that changes to signature or
|
|
247
|
+
# defaults stay consistent!
|
|
248
|
+
|
|
249
|
+
max_evaluations = 100 * max_iter
|
|
250
|
+
if n_print > max_iter:
|
|
251
|
+
warnings.warn("n_print larger than max_iter, adjusting to n_print=max_iter")
|
|
252
|
+
n_print = max_iter
|
|
253
|
+
|
|
254
|
+
if units not in LAMMPS_UNIT_CONVERSIONS.keys():
|
|
255
|
+
raise NotImplementedError
|
|
256
|
+
energy_units = LAMMPS_UNIT_CONVERSIONS[units]["energy"]
|
|
257
|
+
force_units = LAMMPS_UNIT_CONVERSIONS[units]["force"]
|
|
258
|
+
|
|
259
|
+
ionic_energy_tolerance *= energy_units
|
|
260
|
+
ionic_force_tolerance *= force_units
|
|
261
|
+
|
|
262
|
+
line_lst = ["variable thermotime equal {} ".format(n_print)]
|
|
263
|
+
line_lst += _get_thermo()
|
|
264
|
+
if pressure is not None:
|
|
265
|
+
if rotation_matrix is None:
|
|
266
|
+
if structure is None:
|
|
267
|
+
raise ValueError(
|
|
268
|
+
"No rotation matrix given while trying to convert pressure. "
|
|
269
|
+
"This is most likely due to no structure being defined."
|
|
270
|
+
)
|
|
271
|
+
else:
|
|
272
|
+
rotation_matrix, structure = _get_rotation_matrix(
|
|
273
|
+
structure=structure, pressure=pressure
|
|
274
|
+
)
|
|
275
|
+
# force_skewed = False
|
|
276
|
+
pressure = _pressure_to_lammps(
|
|
277
|
+
pressure=pressure, rotation_matrix=rotation_matrix, units=units
|
|
278
|
+
)
|
|
279
|
+
if np.isscalar(pressure):
|
|
280
|
+
str_press = " iso {}".format(pressure)
|
|
281
|
+
else:
|
|
282
|
+
str_press = ""
|
|
283
|
+
for ii, (press, str_axis) in enumerate(
|
|
284
|
+
zip(pressure, ["x", "y", "z", "xy", "xz", "yz"])
|
|
285
|
+
):
|
|
286
|
+
if press is not None:
|
|
287
|
+
str_press += " {} {}".format(str_axis, press)
|
|
288
|
+
# if ii > 2:
|
|
289
|
+
# force_skewed = True
|
|
290
|
+
if len(str_press) > 1:
|
|
291
|
+
str_press += " couple none"
|
|
292
|
+
line_lst += [
|
|
293
|
+
"fix ensemble all box/relax" + str_press,
|
|
294
|
+
]
|
|
295
|
+
line_lst += [
|
|
296
|
+
"min_style " + style,
|
|
297
|
+
"minimize "
|
|
298
|
+
+ str(ionic_energy_tolerance)
|
|
299
|
+
+ " "
|
|
300
|
+
+ str(ionic_force_tolerance)
|
|
301
|
+
+ " "
|
|
302
|
+
+ str(int(max_iter))
|
|
303
|
+
+ " "
|
|
304
|
+
+ str(int(max_evaluations)),
|
|
305
|
+
]
|
|
306
|
+
return line_lst, structure
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def calc_static():
|
|
310
|
+
return ["variable thermotime equal 1"] + _get_thermo() + ["run 0"]
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _get_thermo():
|
|
314
|
+
return [
|
|
315
|
+
"thermo_style custom step temp pe etotal pxx pxy pxz pyy pyz pzz vol",
|
|
316
|
+
"thermo_modify format float %20.15g",
|
|
317
|
+
"thermo ${thermotime}",
|
|
318
|
+
]
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _is_isotropic_hydrostatic(pressure):
|
|
322
|
+
axial_all_alike = None not in pressure[:3] and np.allclose(
|
|
323
|
+
pressure[:3], pressure[0]
|
|
324
|
+
)
|
|
325
|
+
shear_all_none = all(p is None for p in pressure[3:])
|
|
326
|
+
shear_all_zero = None not in pressure[3:] and np.allclose(pressure[3:], 0)
|
|
327
|
+
return axial_all_alike and (shear_all_none or shear_all_zero)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _set_initial_velocity(
|
|
331
|
+
temperature,
|
|
332
|
+
seed=80996,
|
|
333
|
+
gaussian=False,
|
|
334
|
+
append_value=False,
|
|
335
|
+
zero_lin_momentum=True,
|
|
336
|
+
zero_rot_momentum=True,
|
|
337
|
+
):
|
|
338
|
+
"""
|
|
339
|
+
Create initial velocities via velocity all create. More information can be found on LAMMPS website:
|
|
340
|
+
https://lammps.sandia.gov/doc/velocity.html
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
temperature: (int or float)
|
|
344
|
+
seed: (int) Seed for the initial random number generator
|
|
345
|
+
gaussian: (True/False) Create velocity according to the Gaussian distribution (otherwise uniform)
|
|
346
|
+
append_value: (True/False) Add the velocity values to the current velocities (probably not functional now)
|
|
347
|
+
zero_lin_momentum: (True/False) Cancel the total linear momentum
|
|
348
|
+
zero_rot_momentum: (True/False) Cancel the total angular momentum
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
arg = ""
|
|
352
|
+
if gaussian:
|
|
353
|
+
arg = " dist gaussian"
|
|
354
|
+
if append_value:
|
|
355
|
+
arg += " sum yes"
|
|
356
|
+
if not zero_lin_momentum:
|
|
357
|
+
arg += " mom no"
|
|
358
|
+
if not zero_rot_momentum:
|
|
359
|
+
arg += " rot no"
|
|
360
|
+
return "velocity all create " + str(temperature) + " " + str(seed) + arg
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _pressure_to_lammps(pressure, rotation_matrix, units="metal"):
|
|
364
|
+
"""
|
|
365
|
+
Convert a singular value, list of values, or combination of values to the appropriate six elements for Lammps
|
|
366
|
+
pxx, pyy, pzz, pxy, pxz, and pyz pressure tensor representation.
|
|
367
|
+
|
|
368
|
+
Lammps handles complex cells in a particular way, namely by using an upper triangular cell. This means we may
|
|
369
|
+
need to convert our pressure tensor to a new coordinate frame. We also handle that transformation here.
|
|
370
|
+
|
|
371
|
+
In case of a single pressure value, it is again returned as a single pressure value, to be used with the "iso"
|
|
372
|
+
option (i.e., coupled deformation in x, y, and z).
|
|
373
|
+
|
|
374
|
+
Finally, we also ensure that the units are converted from pyiron's GPa to whatever Lammps needs.
|
|
375
|
+
|
|
376
|
+
Args:
|
|
377
|
+
pressure (float/list/tuple/numpy.ndarray): The pressure(s) to convert.
|
|
378
|
+
rotation_matrix (numpy.ndarray): The 3x3 matrix rotating from the pyiron to Lammps coordinate frame.
|
|
379
|
+
|
|
380
|
+
Returns:
|
|
381
|
+
(list): pxx, pyy, pzz, pxy, pxz, and pyz to be passed to Lammps.
|
|
382
|
+
|
|
383
|
+
or
|
|
384
|
+
|
|
385
|
+
(float): a single, isotropic pressure to be used with the "iso" option
|
|
386
|
+
"""
|
|
387
|
+
|
|
388
|
+
# in case no rotation matrix is given, assume identity
|
|
389
|
+
if rotation_matrix is None:
|
|
390
|
+
rotation_matrix = np.eye(3)
|
|
391
|
+
|
|
392
|
+
# If pressure is a scalar, only unit conversion is needed.
|
|
393
|
+
if np.isscalar(pressure):
|
|
394
|
+
return float(pressure) * LAMMPS_UNIT_CONVERSIONS[units]["pressure"]
|
|
395
|
+
|
|
396
|
+
# Normalize pressure to a list of 6 entries of either float or NoneType type.
|
|
397
|
+
if len(pressure) > 6:
|
|
398
|
+
raise ValueError(
|
|
399
|
+
"Pressure can have a maximum of 6 values, (x, y, z, xy, xz, and yz), but got "
|
|
400
|
+
+ "{}".format(len(pressure))
|
|
401
|
+
)
|
|
402
|
+
pressure = [float(p) if p is not None else None for p in pressure]
|
|
403
|
+
pressure += (6 - len(pressure)) * [None]
|
|
404
|
+
|
|
405
|
+
if all(p is None for p in pressure):
|
|
406
|
+
raise ValueError("Pressure cannot have a length but all be None")
|
|
407
|
+
|
|
408
|
+
# If necessary, rotate the pressure tensor to the Lammps coordinate frame.
|
|
409
|
+
# Isotropic, hydrostatic pressures are rotation invariant.
|
|
410
|
+
if not np.isclose(
|
|
411
|
+
np.matrix.trace(rotation_matrix), 3
|
|
412
|
+
) and not _is_isotropic_hydrostatic(pressure):
|
|
413
|
+
if any(p is None for p in pressure):
|
|
414
|
+
raise ValueError(
|
|
415
|
+
"Cells which are not orthorhombic or an upper-triangular cell are incompatible with Lammps "
|
|
416
|
+
"constant pressure calculations unless the entire pressure tensor is defined. "
|
|
417
|
+
"The reason is that Lammps demands such cells be represented with an "
|
|
418
|
+
"upper-triangular unit cell, thus a rotation between Lammps and pyiron coordinate "
|
|
419
|
+
"frames is required; it is not possible to rotate the pressure tensor if any of "
|
|
420
|
+
"its components is None."
|
|
421
|
+
)
|
|
422
|
+
pxx, pyy, pzz, pxy, pxz, pyz = pressure
|
|
423
|
+
pressure_tensor = np.array([[pxx, pxy, pxz], [pxy, pyy, pyz], [pxz, pyz, pzz]])
|
|
424
|
+
lammps_pressure_tensor = rotation_matrix.T @ pressure_tensor @ rotation_matrix
|
|
425
|
+
pressure = list(lammps_pressure_tensor[[0, 1, 2, 0, 0, 1], [0, 1, 2, 1, 2, 2]])
|
|
426
|
+
|
|
427
|
+
return [
|
|
428
|
+
(p * LAMMPS_UNIT_CONVERSIONS[units]["pressure"] if p is not None else p)
|
|
429
|
+
for p in pressure
|
|
430
|
+
]
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def _get_rotation_matrix(structure, pressure):
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
Args:
|
|
437
|
+
pressure:
|
|
438
|
+
|
|
439
|
+
Returns:
|
|
440
|
+
|
|
441
|
+
"""
|
|
442
|
+
if structure is not None:
|
|
443
|
+
prism = UnfoldingPrism(structure.cell)
|
|
444
|
+
|
|
445
|
+
structure = _modify_structure_to_allow_requested_deformation(
|
|
446
|
+
pressure=pressure, structure=structure, prism=prism
|
|
447
|
+
)
|
|
448
|
+
rotation_matrix = prism.R
|
|
449
|
+
else:
|
|
450
|
+
warnings.warn("No structure set, can not validate the simulation cell!")
|
|
451
|
+
rotation_matrix = None
|
|
452
|
+
return rotation_matrix, structure
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def _modify_structure_to_allow_requested_deformation(structure, pressure, prism=None):
|
|
456
|
+
"""
|
|
457
|
+
Lammps will not allow xy/xz/yz cell deformations in minimization or MD for non-triclinic cells. In case the
|
|
458
|
+
requested pressure for a calculation has these non-diagonal entries, we need to make sure it will run. One way
|
|
459
|
+
to do this is by invoking the lammps `change_box` command, but it is easier to just force our box to to be
|
|
460
|
+
triclinic by adding a very small cell perturbation (in the case where it isn't triclinic already).
|
|
461
|
+
|
|
462
|
+
Args:
|
|
463
|
+
pressure (float/int/list/numpy.ndarray/tuple): Between three and six pressures for the x, y, z, xy, xz, and
|
|
464
|
+
yz directions, in that order, or a single value.
|
|
465
|
+
"""
|
|
466
|
+
if hasattr(pressure, "__len__"):
|
|
467
|
+
non_diagonal_pressures = np.any([p is not None for p in pressure[3:]])
|
|
468
|
+
|
|
469
|
+
if prism is None:
|
|
470
|
+
prism = UnfoldingPrism(structure.cell)
|
|
471
|
+
|
|
472
|
+
if non_diagonal_pressures:
|
|
473
|
+
try:
|
|
474
|
+
if not prism.is_skewed():
|
|
475
|
+
skew_structure = structure.copy()
|
|
476
|
+
skew_structure.cell[0, 1] += 2 * prism.acc
|
|
477
|
+
return skew_structure
|
|
478
|
+
except AttributeError:
|
|
479
|
+
warnings.warn(
|
|
480
|
+
"WARNING: Setting a calculation type which uses pressure before setting the structure risks "
|
|
481
|
+
+ "constraining your cell shape evolution if non-diagonal pressures are used but the structure "
|
|
482
|
+
+ "is not triclinic from the start of the calculation."
|
|
483
|
+
)
|
|
484
|
+
return structure
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from ase.atoms import Atoms
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _get_fixed_atom_boolean_vector(structure: Atoms):
|
|
6
|
+
fixed_atom_vector = np.array([[False, False, False]] * len(structure))
|
|
7
|
+
for c in structure.constraints:
|
|
8
|
+
c_dict = c.todict()
|
|
9
|
+
if c_dict["name"] == "FixAtoms":
|
|
10
|
+
fixed_atom_vector[c_dict["kwargs"]["indices"]] = [True, True, True]
|
|
11
|
+
elif c_dict["name"] == "FixedPlane":
|
|
12
|
+
if all(np.isin(c_dict["kwargs"]["direction"], [0, 1, 1 / np.sqrt(2)])):
|
|
13
|
+
if "indices" in c_dict["kwargs"]:
|
|
14
|
+
fixed_atom_vector[c_dict["kwargs"]["indices"]] = np.array(
|
|
15
|
+
c_dict["kwargs"]["direction"]
|
|
16
|
+
).astype(bool)
|
|
17
|
+
elif "a" in c_dict["kwargs"]:
|
|
18
|
+
fixed_atom_vector[c_dict["kwargs"]["a"]] = np.array(
|
|
19
|
+
c_dict["kwargs"]["direction"]
|
|
20
|
+
).astype(bool)
|
|
21
|
+
else:
|
|
22
|
+
raise ValueError(
|
|
23
|
+
"Currently the directions are limited to [1, 0, 0], [1, 1, 0], [1, 1, 1] and its permutations."
|
|
24
|
+
)
|
|
25
|
+
else:
|
|
26
|
+
raise ValueError("Only FixAtoms and FixedPlane are currently supported. ")
|
|
27
|
+
return fixed_atom_vector
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def set_selective_dynamics(structure: Atoms, calc_md: bool = False):
|
|
31
|
+
control_dict = {}
|
|
32
|
+
if len(structure.constraints) > 0:
|
|
33
|
+
sel_dyn = _get_fixed_atom_boolean_vector(structure=structure)
|
|
34
|
+
# Enter loop only if constraints present
|
|
35
|
+
if len(np.argwhere(np.any(sel_dyn, axis=1)).flatten()) != 0:
|
|
36
|
+
all_indices = np.arange(len(structure), dtype=int)
|
|
37
|
+
constraint_xyz = np.argwhere(np.all(sel_dyn, axis=1)).flatten()
|
|
38
|
+
not_constrained_xyz = np.setdiff1d(all_indices, constraint_xyz)
|
|
39
|
+
# LAMMPS starts counting from 1
|
|
40
|
+
constraint_xyz += 1
|
|
41
|
+
ind_x = np.argwhere(sel_dyn[not_constrained_xyz, 0]).flatten()
|
|
42
|
+
ind_y = np.argwhere(sel_dyn[not_constrained_xyz, 1]).flatten()
|
|
43
|
+
ind_z = np.argwhere(sel_dyn[not_constrained_xyz, 2]).flatten()
|
|
44
|
+
constraint_xy = not_constrained_xyz[np.intersect1d(ind_x, ind_y)] + 1
|
|
45
|
+
constraint_yz = not_constrained_xyz[np.intersect1d(ind_y, ind_z)] + 1
|
|
46
|
+
constraint_zx = not_constrained_xyz[np.intersect1d(ind_z, ind_x)] + 1
|
|
47
|
+
constraint_x = (
|
|
48
|
+
not_constrained_xyz[np.setdiff1d(np.setdiff1d(ind_x, ind_y), ind_z)] + 1
|
|
49
|
+
)
|
|
50
|
+
constraint_y = (
|
|
51
|
+
not_constrained_xyz[np.setdiff1d(np.setdiff1d(ind_y, ind_z), ind_x)] + 1
|
|
52
|
+
)
|
|
53
|
+
constraint_z = (
|
|
54
|
+
not_constrained_xyz[np.setdiff1d(np.setdiff1d(ind_z, ind_x), ind_y)] + 1
|
|
55
|
+
)
|
|
56
|
+
control_dict = {}
|
|
57
|
+
if len(constraint_xyz) > 0:
|
|
58
|
+
control_dict["group constraintxyz"] = "id " + " ".join(
|
|
59
|
+
[str(ind) for ind in constraint_xyz]
|
|
60
|
+
)
|
|
61
|
+
control_dict["fix constraintxyz"] = "constraintxyz setforce 0.0 0.0 0.0"
|
|
62
|
+
if calc_md:
|
|
63
|
+
control_dict["velocity constraintxyz"] = "set 0.0 0.0 0.0"
|
|
64
|
+
if len(constraint_xy) > 0:
|
|
65
|
+
control_dict["group constraintxy"] = "id " + " ".join(
|
|
66
|
+
[str(ind) for ind in constraint_xy]
|
|
67
|
+
)
|
|
68
|
+
control_dict["fix constraintxy"] = "constraintxy setforce 0.0 0.0 NULL"
|
|
69
|
+
if calc_md:
|
|
70
|
+
control_dict["velocity constraintxy"] = "set 0.0 0.0 NULL"
|
|
71
|
+
if len(constraint_yz) > 0:
|
|
72
|
+
control_dict["group constraintyz"] = "id " + " ".join(
|
|
73
|
+
[str(ind) for ind in constraint_yz]
|
|
74
|
+
)
|
|
75
|
+
control_dict["fix constraintyz"] = "constraintyz setforce NULL 0.0 0.0"
|
|
76
|
+
if calc_md:
|
|
77
|
+
control_dict["velocity constraintyz"] = "set NULL 0.0 0.0"
|
|
78
|
+
if len(constraint_zx) > 0:
|
|
79
|
+
control_dict["group constraintxz"] = "id " + " ".join(
|
|
80
|
+
[str(ind) for ind in constraint_zx]
|
|
81
|
+
)
|
|
82
|
+
control_dict["fix constraintxz"] = "constraintxz setforce 0.0 NULL 0.0"
|
|
83
|
+
if calc_md:
|
|
84
|
+
control_dict["velocity constraintxz"] = "set 0.0 NULL 0.0"
|
|
85
|
+
if len(constraint_x) > 0:
|
|
86
|
+
control_dict["group constraintx"] = "id " + " ".join(
|
|
87
|
+
[str(ind) for ind in constraint_x]
|
|
88
|
+
)
|
|
89
|
+
control_dict["fix constraintx"] = "constraintx setforce 0.0 NULL NULL"
|
|
90
|
+
if calc_md:
|
|
91
|
+
control_dict["velocity constraintx"] = "set 0.0 NULL NULL"
|
|
92
|
+
if len(constraint_y) > 0:
|
|
93
|
+
control_dict["group constrainty"] = "id " + " ".join(
|
|
94
|
+
[str(ind) for ind in constraint_y]
|
|
95
|
+
)
|
|
96
|
+
control_dict["fix constrainty"] = "constrainty setforce NULL 0.0 NULL"
|
|
97
|
+
if calc_md:
|
|
98
|
+
control_dict["velocity constrainty"] = "set NULL 0.0 NULL"
|
|
99
|
+
if len(constraint_z) > 0:
|
|
100
|
+
control_dict["group constraintz"] = "id " + " ".join(
|
|
101
|
+
[str(ind) for ind in constraint_z]
|
|
102
|
+
)
|
|
103
|
+
control_dict["fix constraintz"] = "constraintz setforce NULL NULL 0.0"
|
|
104
|
+
if calc_md:
|
|
105
|
+
control_dict["velocity constraintz"] = "set NULL NULL 0.0"
|
|
106
|
+
return control_dict
|