Skip to content

Commit 91eb7af

Browse files
authored
Merge pull request #234 from jan-janssen/external_lmp
External Lammps Library
2 parents 0448fba + c6c2c97 commit 91eb7af

File tree

8 files changed

+76
-62
lines changed

8 files changed

+76
-62
lines changed

calphy/alchemy.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class Alchemy(cph.Phase):
5353
5454
"""
5555

56-
def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
56+
def __init__(self, calculation=None, simfolder=None, log_to_screen=False, lmp=None):
5757

5858
# call base class
5959
super().__init__(
60-
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen
60+
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen, lmp=lmp,
6161
)
6262

6363
def run_averaging(self):
@@ -82,11 +82,12 @@ def run_averaging(self):
8282
At the end of the run, the averaged box dimensions are calculated.
8383
"""
8484
lmp = ph.create_object(
85-
self.cores,
86-
self.simfolder,
87-
self.calc.md.timestep,
88-
self.calc.md.cmdargs,
89-
self.calc.md.init_commands,
85+
cores=self.cores,
86+
directory=self.simfolder,
87+
timestep=self.calc.md.timestep,
88+
cmdargs=self.calc.md.cmdargs,
89+
init_commands=self.calc.md.init_commands,
90+
lmp=self._lmp,
9091
)
9192

9293
lmp.command(f"pair_style {self.calc._pair_style_with_options[0]}")
@@ -156,11 +157,12 @@ def run_integration(self, iteration=1):
156157

157158
# create lammps object
158159
lmp = ph.create_object(
159-
self.cores,
160-
self.simfolder,
161-
self.calc.md.timestep,
162-
self.calc.md.cmdargs,
163-
self.calc.md.init_commands,
160+
cores=self.cores,
161+
directory=self.simfolder,
162+
timestep=self.calc.md.timestep,
163+
cmdargs=self.calc.md.cmdargs,
164+
init_commands=self.calc.md.init_commands,
165+
lmp=self._lmp,
164166
)
165167

166168
# Adiabatic switching parameters.

calphy/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def write(self, infile):
4949

5050

5151
def create_object(
52-
cores, directory, timestep, cmdargs="", init_commands=(), script_mode=False
52+
cores, directory, timestep, cmdargs="", init_commands=(), script_mode=False, lmp=None,
5353
):
5454
"""
5555
Create LAMMPS object
@@ -71,7 +71,7 @@ def create_object(
7171
"""
7272
if script_mode:
7373
lmp = LammpsScript()
74-
else:
74+
elif lmp is None:
7575
if cmdargs == "":
7676
cmdargs = None
7777
elif isinstance(cmdargs, str):

calphy/liquid.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ class Liquid(cph.Phase):
4949
5050
"""
5151

52-
def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
52+
def __init__(self, calculation=None, simfolder=None, log_to_screen=False, lmp=None):
5353
"""
5454
Set up class
5555
"""
5656
# call base class
5757
super().__init__(
58-
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen
58+
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen, lmp=lmp,
5959
)
6060

6161
def rattle_structure(self, lmp):
@@ -166,11 +166,12 @@ def run_averaging(self):
166166
"""
167167
# create lammps object
168168
lmp = ph.create_object(
169-
self.cores,
170-
self.simfolder,
171-
self.calc.md.timestep,
172-
self.calc.md.cmdargs,
173-
self.calc.md.init_commands,
169+
cores=self.cores,
170+
directory=self.simfolder,
171+
timestep=self.calc.md.timestep,
172+
cmdargs=self.calc.md.cmdargs,
173+
init_commands=self.calc.md.init_commands,
174+
lmp=self._lmp,
174175
)
175176

176177
lmp.command(f"pair_style {self.calc._pair_style_with_options[0]}")
@@ -241,11 +242,12 @@ def run_integration(self, iteration=1):
241242
the lambda parameter. See algorithm 4 in publication.
242243
"""
243244
lmp = ph.create_object(
244-
self.cores,
245-
self.simfolder,
246-
self.calc.md.timestep,
247-
self.calc.md.cmdargs,
248-
self.calc.md.init_commands,
245+
cores=self.cores,
246+
directory=self.simfolder,
247+
timestep=self.calc.md.timestep,
248+
cmdargs=self.calc.md.cmdargs,
249+
init_commands=self.calc.md.init_commands,
250+
lmp=self._lmp,
249251
)
250252

251253
# Adiabatic switching parameters.

calphy/phase.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Phase:
5353
5454
"""
5555

56-
def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
56+
def __init__(self, calculation=None, simfolder=None, log_to_screen=False, lmp=None):
5757

5858
self.calc = copy.deepcopy(calculation)
5959

@@ -225,6 +225,7 @@ def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
225225
self.logger.info("pair_style or pair_coeff not provided")
226226
if self.calc.potential_file is not None:
227227
self.logger.info("potential is being loaded from file instead")
228+
self._lmp = lmp
228229

229230
def __repr__(self):
230231
"""
@@ -944,11 +945,13 @@ def reversible_scaling(self, iteration=1):
944945

945946
# create lammps object
946947
lmp = ph.create_object(
947-
self.cores,
948-
self.simfolder,
949-
self.calc.md.timestep,
950-
self.calc.md.cmdargs,
951-
self.calc.md.init_commands,
948+
cores=self.cores,
949+
directory=self.simfolder,
950+
timestep=self.calc.md.timestep,
951+
cmdargs=self.calc.md.cmdargs,
952+
init_commands=self.calc.md.init_commands,
953+
script_mode=False,
954+
lmp=self._lmp,
952955
)
953956

954957
lmp.command("echo log")
@@ -1327,11 +1330,13 @@ def temperature_scaling(self, iteration=1):
13271330

13281331
# create lammps object
13291332
lmp = ph.create_object(
1330-
self.cores,
1331-
self.simfolder,
1332-
self.calc.md.timestep,
1333-
self.calc.md.cmdargs,
1334-
self.calc.md.init_commands,
1333+
cores=self.cores,
1334+
directory=self.simfolder,
1335+
timestep=self.calc.md.timestep,
1336+
cmdargs=self.calc.md.cmdargs,
1337+
init_commands=self.calc.md.init_commands,
1338+
script_mode=False,
1339+
lmp=self._lmp,
13351340
)
13361341

13371342
lmp.command("echo log")
@@ -1473,11 +1478,13 @@ def pressure_scaling(self, iteration=1):
14731478

14741479
# create lammps object
14751480
lmp = ph.create_object(
1476-
self.cores,
1477-
self.simfolder,
1478-
self.calc.md.timestep,
1479-
self.calc.md.cmdargs,
1480-
self.calc.md.init_commands,
1481+
cores=self.cores,
1482+
directory=self.simfolder,
1483+
timestep=self.calc.md.timestep,
1484+
cmdargs=self.calc.md.cmdargs,
1485+
init_commands=self.calc.md.init_commands,
1486+
script_mode=False,
1487+
lmp=self._lmp,
14811488
)
14821489

14831490
lmp.command("echo log")

calphy/solid.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class Solid(cph.Phase):
5151
5252
"""
5353

54-
def __init__(self, calculation=None, simfolder=None, log_to_screen=False):
54+
def __init__(self, calculation=None, simfolder=None, log_to_screen=False, lmp=None):
5555

5656
# call base class
5757
super().__init__(
58-
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen
58+
calculation=calculation, simfolder=simfolder, log_to_screen=log_to_screen, lmp=lmp,
5959
)
6060

6161
def run_spring_constant_convergence(self, lmp):
@@ -236,12 +236,13 @@ def run_interactive_averaging(self):
236236
"""
237237

238238
lmp = ph.create_object(
239-
self.cores,
240-
self.simfolder,
241-
self.calc.md.timestep,
242-
self.calc.md.cmdargs,
243-
init_commands=self.calc.md.init_commands,
239+
cores=self.cores,
240+
directory=self.simfolder,
241+
timestep=self.calc.md.timestep,
242+
cmdargs=self.calc.md.cmdargs,
243+
init_commands=self.calc.md.init_commands,
244244
script_mode=self.calc.script_mode,
245+
lmp=self._lmp,
245246
)
246247

247248
# set up potential
@@ -324,12 +325,13 @@ def run_minimal_averaging(self):
324325
At the end of the run, the averaged box dimensions are calculated.
325326
"""
326327
lmp = ph.create_object(
327-
self.cores,
328-
self.simfolder,
329-
self.calc.md.timestep,
330-
self.calc.md.cmdargs,
331-
init_commands=self.calc.md.init_commands,
328+
cores=self.cores,
329+
directory=self.simfolder,
330+
timestep=self.calc.md.timestep,
331+
cmdargs=self.calc.md.cmdargs,
332+
init_commands=self.calc.md.init_commands,
332333
script_mode=self.calc.script_mode,
334+
lmp=self._lmp,
333335
)
334336

335337
# set up potential
@@ -407,12 +409,13 @@ def run_integration(self, iteration=1):
407409
the lambda parameter. See algorithm 4 in publication.
408410
"""
409411
lmp = ph.create_object(
410-
self.cores,
411-
self.simfolder,
412-
self.calc.md.timestep,
413-
self.calc.md.cmdargs,
414-
init_commands=self.calc.md.init_commands,
412+
cores=self.cores,
413+
directory=self.simfolder,
414+
timestep=self.calc.md.timestep,
415+
cmdargs=self.calc.md.cmdargs,
416+
init_commands=self.calc.md.init_commands,
415417
script_mode=self.calc.script_mode,
418+
lmp=self._lmp,
416419
)
417420

418421
# set up potential

docs/source/gettingstarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The environment is now set up to run calphy.
8787

8888
- lammps `conda install -c conda-forge lammps`
8989
- mendeleev >=0.7.0 `pip install mendeleev`
90-
- pylammpsmpi >=0.0.8 `pip install pylammpsmpi`
90+
- pylammpsmpi >=0.3.0 `pip install pylammpsmpi`
9191
- pyscal >=2.10.14 `pip install git+https://github.com/srmnitc/pyscal`
9292
- pyyaml >=5.4.1 `pip install pyyaml`
9393
- scipy >=1.7.0 `pip install scipy`

environment-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
- mendeleev
99
- openmpi
1010
- mpi4py
11-
- pylammpsmpi >=0.0.9
11+
- pylammpsmpi >=0.3.0
1212
- pyscal3
1313
- matplotlib
1414
- tqdm

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- openmpi
1212
- numpy
1313
- mpi4py
14-
- pylammpsmpi
14+
- pylammpsmpi >=0.3.0
1515
- matplotlib
1616
- tqdm
1717
- uncertainties

0 commit comments

Comments
 (0)