/
interactive.py
716 lines (646 loc) · 27.3 KB
/
interactive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
from ctypes import c_double, c_int
import importlib
import numpy as np
import os
import pandas as pd
import pickle
import subprocess
import warnings
from scipy import constants
from pyiron.lammps.base import LammpsBase
from pyiron.lammps.structure import UnfoldingPrism
from pyiron.atomistics.job.interactive import GenericInteractive
__author__ = "Osamu Waseda, Jan Janssen"
__copyright__ = (
"Copyright 2019, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "production"
__date__ = "Sep 1, 2018"
class LammpsInteractive(LammpsBase, GenericInteractive):
def __init__(self, project, job_name):
super(LammpsInteractive, self).__init__(project, job_name)
self._check_opened = False
self._interactive_prism = None
self._interactive_run_command = None
self._interactive_grand_canonical = True
self.interactive_cache = {
"cells": [],
"energy_pot": [],
"energy_tot": [],
"forces": [],
"positions": [],
"pressures": [],
"steps": [],
"indices": [],
"temperature": [],
"computation_time": [],
"volume": [],
}
@property
def structure(self):
return GenericInteractive.structure.fget(self)
@structure.setter
def structure(self, structure):
GenericInteractive.structure.fset(self, structure)
def get_structure(self, iteration_step=-1, wrap_atoms=True):
return GenericInteractive.get_structure(
self, iteration_step=iteration_step, wrap_atoms=wrap_atoms
)
def _interactive_lib_command(self, command):
self._logger.debug("Lammps library: " + command)
self._interactive_library.command(command)
def interactive_positions_getter(self):
positions = np.reshape(
np.array(self._interactive_library.gather_atoms("x", 1, 3)),
(len(self.structure), 3),
)
if np.matrix.trace(self._interactive_prism.R) != 3:
positions = np.dot(positions, self._interactive_prism.R.T)
return positions.tolist()
def interactive_positions_setter(self, positions):
if np.matrix.trace(self._interactive_prism.R) != 3:
positions = np.array(positions).reshape(-1, 3)
positions = np.dot(positions, self._interactive_prism.R)
positions = np.array(positions).flatten()
if self.server.run_mode.interactive and self.server.cores == 1:
self._interactive_library.scatter_atoms(
"x", 1, 3, (len(positions) * c_double)(*positions)
)
else:
self._interactive_library.scatter_atoms("x", 1, 3, positions)
self._interactive_lib_command("change_box all remap")
def interactive_cells_getter(self):
cc = np.array(
[
[self._interactive_library.get_thermo("lx"), 0, 0],
[
self._interactive_library.get_thermo("xy"),
self._interactive_library.get_thermo("ly"),
0,
],
[
self._interactive_library.get_thermo("xz"),
self._interactive_library.get_thermo("yz"),
self._interactive_library.get_thermo("lz"),
],
]
)
return self._interactive_prism.unfold_cell(cc)
def interactive_cells_setter(self, cell):
self._interactive_prism = UnfoldingPrism(cell)
lx, ly, lz, xy, xz, yz = self._interactive_prism.get_lammps_prism()
if np.matrix.trace(self._interactive_prism.R) != 3:
warnings.warn(
"Warning: setting upper trangular matrix might slow down the calculation"
)
if self._interactive_prism.is_skewed():
if self.structure._is_scaled:
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f triclinic remap units box"
% (lx, ly, lz, xy, xz, yz)
)
else:
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f \
xy final %f xz final %f yz final %f triclinic units box"
% (lx, ly, lz, xy, xz, yz)
)
else:
if self.structure._is_scaled:
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f remap units box"
% (lx, ly, lz)
)
else:
self._interactive_lib_command(
"change_box all x final 0 %f y final 0 %f z final 0 %f units box"
% (lx, ly, lz)
)
def interactive_indices_setter(self, indices):
el_struct_lst = self._structure_current.get_species_symbols()
el_obj_lst = self._structure_current.get_species_objects()
el_eam_lst = self.input.potential.get_element_lst()
el_dict = {}
for id_eam, el_eam in enumerate(el_eam_lst):
if el_eam in el_struct_lst:
id_el = list(el_struct_lst).index(el_eam)
el = el_obj_lst[id_el]
el_dict[el] = id_eam + 1
elem_all = np.array(
[el_dict[self._structure_current.species[el]] for el in indices]
)
if self.server.run_mode.interactive and self.server.cores == 1:
self._interactive_library.scatter_atoms(
"type", 0, 1, (len(elem_all) * c_int)(*elem_all)
)
else:
self._interactive_library.scatter_atoms("type", 0, 1, elem_all)
def interactive_volume_getter(self):
return self._interactive_library.get_thermo("vol")
def interactive_forces_getter(self):
ff = np.reshape(
np.array(self._interactive_library.gather_atoms("f", 1, 3)),
(len(self.structure), 3),
)
if np.matrix.trace(self._interactive_prism.R) != 3:
ff = np.dot(ff, self._interactive_prism.R.T)
return ff.tolist()
def interactive_execute(self):
self._interactive_lib_command(self._interactive_run_command)
def _interactive_lammps_input(self):
del self.input.control["dump___1"]
del self.input.control["dump_modify___1"]
for key, value in zip(
self.input.control.dataset["Parameter"], self.input.control.dataset["Value"]
):
if key in [
"read_data",
"units",
"dimension",
"boundary",
"atom_style",
"atom_modify",
"include",
"run",
"minimize",
]:
continue
else:
self._interactive_lib_command(
" ".join(key.split(self.input.control.multi_word_separator))
+ " "
+ str(value)
)
def _interactive_set_potential(self):
potential_lst = []
if self.input.potential.files is not None:
for potential in self.input.potential.files:
if not os.path.exists(potential):
raise ValueError("Potential not found: ", potential)
potential_lst.append([potential.split("/")[-1], potential])
style_full = self.input.control["atom_style"] == "full"
for line in self.input.potential.get_string_lst():
if len(line) > 2:
for potential in potential_lst:
if potential[0] in line:
line = line.replace(potential[0], potential[1])
# Don't write the kspace_style or pair style commands if the atom style is "full"
if not (style_full and ("kspace" in line or "pair" in line)):
self._interactive_lib_command(line.split("\n")[0])
if style_full:
# Currently supports only water molecules. Please feel free to expand this
self._interactive_water_setter()
def _executable_activate_mpi(self):
if (
self.server.run_mode.interactive
or self.server.run_mode.interactive_non_modal
):
pass
else:
super(LammpsInteractive, self)._executable_activate_mpi()
def _reset_interactive_run_command(self):
df = pd.DataFrame(self.input.control.dataset)
self._interactive_run_command = " ".join(df.T[df.index[-1]].values)
def interactive_initialize_interface(self):
if self.server.run_mode.interactive and self.server.cores == 1:
lammps = getattr(importlib.import_module("lammps"), "lammps")
self._interactive_library = lammps(cmdargs=["-screen", "none"])
else:
self._create_working_directory()
self._interactive_library = LammpsLibrary(
cores=self.server.cores, working_directory=self.working_directory
)
if not all(self.structure.pbc):
self.input.control["boundary"] = " ".join(
["p" if coord else "f" for coord in self.structure.pbc]
)
self._reset_interactive_run_command()
self.interactive_structure_setter(self.structure)
def calc_minimize(
self, e_tol=0.0, f_tol=1e-4, max_iter=1000, pressure=None, n_print=100
):
"""
Sets parameters required for minimisation
Args:
e_tol (float): If the magnitude of difference between energies of two consecutive steps is lower
than or equal to e_tol, the minimisation terminates and is considered converged. (Default: 0.0)
f_tol (float): If the magnitude of the global force vector at a step is lower than or equal to
f_tol, the minimisation terminates and is considered converged. (Default: 1e-4)
max_iter (int): Maximum number of minimisation steps to carry out. If the minimisation converges
before 'max_iter' steps, terminate at the converged step. If the minimisation does
not converge up to 'max_iter' steps, terminate at the 'max_iter' step. Default: 1000)
pressure (float): Pressure at which minimisation is to be carried out. If 'None', isochoric
(constant volume) condition will be used. (Default: None)
n_print (int): Write (dump or print) to the output file every n steps (Default: 100)
"""
if self.server.run_mode.interactive_non_modal:
warnings.warn(
"calc_minimize() is not implemented for the non modal interactive mode use calc_static()!"
)
super(LammpsInteractive, self).calc_minimize(
e_tol=e_tol,
f_tol=f_tol,
max_iter=max_iter,
pressure=pressure,
n_print=n_print,
)
if self.interactive_is_activated() and (
self.server.run_mode.interactive
or self.server.run_mode.interactive_non_modal
):
self.interactive_structure_setter(self.structure)
def calc_md(
self,
temperature=None,
pressure=None,
n_ionic_steps=1000,
time_step=1.0,
n_print=100,
temperature_damping_timescale=100.0,
pressure_damping_timescale=1000.0,
seed=None,
tloop=None,
initial_temperature=None,
langevin=False,
delta_temp=None,
delta_press=None,
):
super(LammpsInteractive, self).calc_md(
temperature=temperature,
pressure=pressure,
n_ionic_steps=n_ionic_steps,
time_step=time_step,
n_print=n_print,
temperature_damping_timescale=temperature_damping_timescale,
pressure_damping_timescale=pressure_damping_timescale,
seed=seed,
tloop=tloop,
initial_temperature=initial_temperature,
langevin=langevin,
delta_temp=delta_temp,
delta_press=delta_press,
)
if self.interactive_is_activated() and (
self.server.run_mode.interactive
or self.server.run_mode.interactive_non_modal
):
self.interactive_structure_setter(self.structure)
def run_if_interactive(self):
if self._generic_input["calc_mode"] == "md":
self.input.control["run"] = self._generic_input["n_print"]
super(LammpsInteractive, self).run_if_interactive()
self._reset_interactive_run_command()
counter = 0
iteration_max = int(
self._generic_input["n_ionic_steps"] / self._generic_input["n_print"]
)
while counter < iteration_max:
self.interactive_execute()
self.interactive_collect()
counter += 1
else:
super(LammpsInteractive, self).run_if_interactive()
self.interactive_execute()
self.interactive_collect()
def run_if_interactive_non_modal(self):
if not self._interactive_fetch_completed:
print("Warning: interactive_fetch being effectuated")
self.interactive_fetch()
super(LammpsInteractive, self).run_if_interactive()
self.interactive_execute()
self._interactive_fetch_completed = False
def interactive_fetch(self):
if (
self._interactive_fetch_completed
and self.server.run_mode.interactive_non_modal
):
print("First run and then fetch")
else:
self.interactive_collect()
self._logger.debug("interactive run - done")
def interactive_structure_setter(self, structure):
self._interactive_lib_command("clear")
self._set_selective_dynamics()
self._interactive_lib_command("units " + self.input.control["units"])
self._interactive_lib_command(
"dimension " + str(self.input.control["dimension"])
)
self._interactive_lib_command("boundary " + self.input.control["boundary"])
self._interactive_lib_command("atom_style " + self.input.control["atom_style"])
self._interactive_lib_command("atom_modify map array")
self._interactive_prism = UnfoldingPrism(structure.cell)
if np.matrix.trace(self._interactive_prism.R) != 3:
warnings.warn(
"Warning: setting upper trangular matrix might slow down the calculation"
)
xhi, yhi, zhi, xy, xz, yz = self._interactive_prism.get_lammps_prism()
if self._interactive_prism.is_skewed():
self._interactive_lib_command(
"region 1 prism"
+ " 0.0 "
+ str(xhi)
+ " 0.0 "
+ str(yhi)
+ " 0.0 "
+ str(zhi)
+ " "
+ str(xy)
+ " "
+ str(xz)
+ " "
+ str(yz)
+ " units box"
)
else:
self._interactive_lib_command(
"region 1 block"
+ " 0.0 "
+ str(xhi)
+ " 0.0 "
+ str(yhi)
+ " 0.0 "
+ str(zhi)
+ " units box"
)
el_struct_lst = self.structure.get_species_symbols()
el_obj_lst = self.structure.get_species_objects()
el_eam_lst = self.input.potential.get_element_lst()
if self.input.control["atom_style"] == "full":
self._interactive_lib_command(
"create_box "
+ str(len(el_eam_lst))
+ " 1 "
+ "bond/types 1 "
+ "angle/types 1 "
+ "extra/bond/per/atom 2 "
+ "extra/angle/per/atom 2 "
)
else:
self._interactive_lib_command("create_box " + str(len(el_eam_lst)) + " 1")
el_dict = {}
for id_eam, el_eam in enumerate(el_eam_lst):
if el_eam in el_struct_lst:
id_el = list(el_struct_lst).index(el_eam)
el = el_obj_lst[id_el]
el_dict[el] = id_eam + 1
self._interactive_lib_command(
"mass {0:3d} {1:f}".format(id_eam + 1, el.AtomicMass)
)
else:
self._interactive_lib_command(
"mass {0:3d} {1:f}".format(id_eam + 1, 1.00)
)
self._interactive_lib_command(
"create_atoms 1 random " + str(len(structure)) + " 12345 1"
)
positions = structure.positions.flatten()
if np.matrix.trace(self._interactive_prism.R) != 3:
positions = np.array(positions).reshape(-1, 3)
positions = np.dot(positions, self._interactive_prism.R)
positions = positions.flatten()
elem_all = np.array([el_dict[el] for el in structure.get_chemical_elements()])
if self.server.run_mode.interactive and self.server.cores == 1:
self._interactive_library.scatter_atoms(
"x", 1, 3, (len(positions) * c_double)(*positions)
)
self._interactive_library.scatter_atoms(
"type", 0, 1, (len(elem_all) * c_int)(*elem_all)
)
else:
self._interactive_library.scatter_atoms("x", 1, 3, positions)
self._interactive_library.scatter_atoms("type", 0, 1, elem_all)
self._interactive_lib_command("change_box all remap")
# if self.input.control['atom_style'] == "full":
# Do not scatter or manipulate when you have water/ use atom_style full in your system
# self._interactive_water_setter()
self._interactive_lammps_input()
self._interactive_set_potential()
def _interactive_water_setter(self):
"""
This function writes the bonds for water molecules present in the structure. It is assumed that only intact
water molecules are present and the H atoms are within 1.3 $\AA$ of each O atom. Once the neighbor list is
generated, the bonds and angles are created. This function needs to be generalized/extended to account for
dissociated water. This function can also be used as an example to create bonds between other molecules.
"""
neighbors = self.structure.get_neighbors(cutoff=1.3)
o_indices = self.structure.select_index("O")
h_indices = self.structure.select_index("H")
h1_indices = np.intersect1d(
np.vstack(neighbors.indices[o_indices])[:, 0], h_indices
)
h2_indices = np.intersect1d(
np.vstack(neighbors.indices[o_indices])[:, 1], h_indices
)
o_ind_str = (
np.array2string(o_indices + 1).replace("[", "").replace("]", "").strip()
)
h1_ind_str = (
np.array2string(h1_indices + 1).replace("[", "").replace("]", "").strip()
)
h2_ind_str = (
np.array2string(h2_indices + 1).replace("[", "").replace("]", "").strip()
)
group_o = "group Oatoms id {}".format(o_ind_str).replace(" ", " ")
group_h1 = "group H1atoms id {}".format(h1_ind_str).replace(" ", " ")
group_h2 = "group H2atoms id {}".format(h2_ind_str).replace(" ", " ")
self._interactive_lib_command(group_o)
self._interactive_lib_command(group_h1)
self._interactive_lib_command(group_h2)
# A dummy pair style that does not have any Coulombic interactions needs to be initialized to create the bonds
self._interactive_lib_command("pair_style lj/cut 2.5")
self._interactive_lib_command("pair_coeff * * 0.0 0.0")
self._interactive_lib_command("create_bonds many Oatoms H1atoms 1 0.7 1.4")
self._interactive_lib_command("create_bonds many Oatoms H2atoms 1 0.7 1.4")
for i, o_ind in enumerate(o_indices):
self._interactive_lib_command(
"create_bonds single/angle 1 {} {} {}".format(
int(h1_indices[i]) + 1, int(o_ind) + 1, int(h2_indices[i]) + 1
)
)
# Now the actual pair styles are written
self._interactive_lib_command(
"pair_style " + self.input.potential["pair_style"]
)
values = np.array(self.input.potential._dataset["Value"])
pair_val = values[
["pair_coeff" in val for val in self.input.potential._dataset["Parameter"]]
]
for val in pair_val:
self._interactive_lib_command("pair_coeff " + val)
self._interactive_lib_command(
"kspace_style " + self.input.potential["kspace_style"]
)
def from_hdf(self, hdf=None, group_name=None):
"""
Recreates instance from the hdf5 file
Args:
hdf (str): Path to the hdf5 file
group_name (str): Name of the group which contains the object
"""
super(LammpsInteractive, self).from_hdf(hdf=hdf, group_name=group_name)
self.species_from_hdf()
def collect_output(self):
if (
self.server.run_mode.interactive
or self.server.run_mode.interactive_non_modal
):
pass
else:
super(LammpsInteractive, self).collect_output()
def update_potential(self):
self._interactive_lib_command(self.potential.Config[0][0])
self._interactive_lib_command(self.potential.Config[0][1])
def interactive_indices_getter(self):
return super(LammpsInteractive, self).interactive_indices_getter().tolist()
def interactive_energy_pot_getter(self):
return self._interactive_library.get_thermo("pe")
def interactive_energy_tot_getter(self):
return self._interactive_library.get_thermo("etotal")
def interactive_steps_getter(self):
return self._interactive_library.get_thermo("step")
def interactive_temperatures_getter(self):
return self._interactive_library.get_thermo("temp")
def interactive_stress_getter(self):
"""
This gives back an Nx3x3 array of stress/atom defined in http://lammps.sandia.gov/doc/compute_stress_atom.html
Keep in mind that it is stress*volume in eV. Further discussion can be found on the website above.
Returns:
numpy.array: Nx3x3 np array of stress/atom
"""
if not "stress" in self.interactive_cache.keys():
self._interactive_lib_command("compute st all stress/atom NULL")
self._interactive_lib_command("run 0")
self.interactive_cache["stress"] = []
id_lst = self._interactive_library.extract_atom("id", 0)
id_lst = np.array([id_lst[i] for i in range(len(self.structure))])-1
id_lst = np.arange(len(id_lst))[np.argsort(id_lst)]
ind = np.array([0, 3, 4, 3, 1, 5, 4, 5, 2])
ss = self._interactive_library.extract_compute("st", 1, 2)
ss = np.array([ss[i][j] for i in range(len(self.structure)) for j in range(6)]).reshape(-1, 6)[id_lst]
ss = ss[:, ind].reshape(len(self.structure), 3, 3)/constants.eV*constants.bar*constants.angstrom**3
if np.matrix.trace(self._interactive_prism.R) != 3:
ss = np.einsum('ij,njk->nik', self._interactive_prism.R, ss)
ss = np.einsum('nij,kj->nik', ss, self._interactive_prism.R)
return ss
def interactive_pressures_getter(self):
pp = np.array(
[
[
self._interactive_library.get_thermo("pxx"),
self._interactive_library.get_thermo("pxy"),
self._interactive_library.get_thermo("pxz"),
],
[
self._interactive_library.get_thermo("pxy"),
self._interactive_library.get_thermo("pyy"),
self._interactive_library.get_thermo("pyz"),
],
[
self._interactive_library.get_thermo("pxz"),
self._interactive_library.get_thermo("pyz"),
self._interactive_library.get_thermo("pzz"),
],
]
)
if np.matrix.trace(self._interactive_prism.R) != 3:
pp = np.dot(
np.dot(self._interactive_prism.R, pp), self._interactive_prism.R.T
)
return pp / 10000 # bar -> GPa
def interactive_close(self):
if self.interactive_is_activated():
self._interactive_library.close()
with self.project_hdf5.open("output") as h5:
if "interactive" in h5.list_groups():
for key in h5["interactive"].list_nodes():
h5["generic/" + key] = h5["interactive/" + key]
super(LammpsInteractive, self).interactive_close()
class LammpsLibrary(object):
def __init__(self, cores=1, working_directory="."):
executable = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "sub", "lmpmpi.py"
)
# print(executable)
self._process = subprocess.Popen(
["mpiexec", "-n", str(cores), "python", executable],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
cwd=working_directory,
)
def _send(self, command, data=None):
"""
Send a command to the Lammps Library executable
Args:
command (str): command to be send to the
data:
"""
# print('send: ', {'c': command, 'd': data})
pickle.dump({"c": command, "d": data}, self._process.stdin)
self._process.stdin.flush()
def _receive(self):
"""
Receive data from the Lammps library
Returns:
data
"""
output = pickle.load(self._process.stdout)
# print(output)
return output
def command(self, command):
"""
Send a command to the lammps library
Args:
command (str):
"""
self._send(command="command", data=command)
def gather_atoms(self, *args):
"""
Gather atoms from the lammps library
Args:
*args:
Returns:
np.array
"""
self._send(command="gather_atoms", data=list(args))
return self._receive()
def scatter_atoms(self, *args):
"""
Scatter atoms for the lammps library
Args:
*args:
"""
self._send(command="scatter_atoms", data=list(args))
def get_thermo(self, *args):
"""
Get thermo from the lammps library
Args:
*args:
Returns:
"""
self._send(command="get_thermo", data=list(args))
return self._receive()
def extract_compute(self, *args):
"""
Extract compute from the lammps library
Args:
*args:
Returns:
"""
self._send(command="extract_compute", data=list(args))
return self._receive()
def close(self):
self._send(command="close")
self._process.kill()
self._process = None
def __del__(self):
if self._process is not None:
self.close()