Skip to content

Commit 7740e83

Browse files
authored
Merge pull request #69 from ICAMS/more_lammps_customisation
More lammps customisation
2 parents 7542a09 + 1dbf5ce commit 7740e83

File tree

11 files changed

+71
-20
lines changed

11 files changed

+71
-20
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.2.6
2+
current_version = 1.2.7
33
commit = True
44
tag = True
55

calphy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from calphy.alchemy import Alchemy
55
from calphy.routines import MeltingTemp
66

7-
__version__ = "1.2.6"
7+
__version__ = "1.2.7"
88

99
def addtest(a,b):
1010
return a+b

calphy/alchemy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def run_averaging(self):
7575
Fix lattice option is not implemented at present.
7676
At the end of the run, the averaged box dimensions are calculated.
7777
"""
78-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
78+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
79+
self.calc.md.cmdargs, self.calc.md.init_commands)
7980

8081
#set up structure
8182
lmp = ph.create_structure(lmp, self.calc)
@@ -138,7 +139,8 @@ def run_integration(self, iteration=1):
138139
"""
139140

140141
#create lammps object
141-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
142+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
143+
self.calc.md.cmdargs, self.calc.md.init_commands)
142144

143145
# Adiabatic switching parameters.
144146
lmp.command("variable li equal 1.0")

calphy/helpers.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
from pyscal.trajectory import Trajectory
3434

3535

36-
def create_object(cores, directory, timestep, cmdargs=None):
36+
def create_object(cores, directory, timestep, cmdargs=None,
37+
init_commands=None):
3738
"""
3839
Create LAMMPS object
3940
@@ -56,11 +57,29 @@ def create_object(cores, directory, timestep, cmdargs=None):
5657
mode="local", cores=cores, working_directory=directory, cmdargs=cmdargs
5758
)
5859

59-
lmp.units("metal")
60-
lmp.boundary("p p p")
61-
lmp.atom_style("atomic")
62-
lmp.timestep(timestep)
63-
lmp.command("box tilt large")
60+
commands = [["units", "metal"],
61+
["boundary", "p p p"],
62+
["atom_style", "atomic"],
63+
["timestep", str(timestep)],
64+
["box", "tilt large"]]
65+
66+
if init_commands is not None:
67+
#we need to replace some initial commands
68+
for rc in init_commands:
69+
#split the command
70+
raw = rc.split()
71+
for x in range(len(commands)):
72+
if raw[0] == commands[x][0]:
73+
#we found a matching command
74+
commands[x] = [rc]
75+
break
76+
else:
77+
#its a new command, add it to the list
78+
commands.append([rc])
79+
80+
for command in commands:
81+
lmp.command(" ".join(command))
82+
6483
return lmp
6584

6685

@@ -338,6 +357,7 @@ def reset_timestep(conf, file="current.data"):
338357
directory=os.path.dirname(file),
339358
timestep=0,
340359
cmdargs=None,
360+
init_commands=None,
341361
)
342362
lmp = read_data(lmp, file)
343363
lmp = write_data(lmp, conf)

calphy/input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def __init__(self):
188188
self.md.thermostat_damping = 0.1
189189
self.md.barostat_damping = 0.1
190190
self.md.cmdargs = None
191+
self.md.init_commands = None
191192

192193
self.nose_hoover = InputTemplate()
193194
self.nose_hoover.thermostat_damping = 0.1

calphy/liquid.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def run_averaging(self):
112112
At the end of the run, the averaged box dimensions are calculated.
113113
"""
114114
#create lammps object
115-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
115+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
116+
self.calc.md.cmdargs, self.calc.md.init_commands)
116117

117118
#set up structure
118119
lmp = ph.create_structure(lmp, self.calc, species=self.calc.n_elements+self.calc._ghost_element_count)
@@ -171,7 +172,8 @@ def run_integration(self, iteration=1):
171172
Run the integration routine where the initial and final systems are connected using
172173
the lambda parameter. See algorithm 4 in publication.
173174
"""
174-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
175+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
176+
self.calc.md.cmdargs, self.calc.md.init_commands)
175177

176178
# Adiabatic switching parameters.
177179
lmp.command("variable li equal 1.0")

calphy/phase.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ def reversible_scaling(self, iteration=1):
671671
pf = lf*pi
672672

673673
#create lammps object
674-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
674+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
675+
self.calc.md.cmdargs, self.calc.md.init_commands)
675676

676677
lmp.command("echo log")
677678
lmp.command("variable li equal %f"%li)
@@ -847,7 +848,8 @@ def temperature_scaling(self, iteration=1):
847848
pf = lf*p0
848849

849850
#create lammps object
850-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
851+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
852+
self.calc.md.cmdargs, self.calc.md.init_commands)
851853

852854
lmp.command("echo log")
853855
lmp.command("variable li equal %f"%li)
@@ -932,7 +934,8 @@ def pressure_scaling(self, iteration=1):
932934
pf = self.calc._pressure_stop
933935

934936
#create lammps object
935-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
937+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
938+
self.calc.md.cmdargs, self.calc.md.init_commands)
936939

937940
lmp.command("echo log")
938941
lmp.command("variable li equal %f"%li)

calphy/solid.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def run_averaging(self):
136136
is calculated.
137137
At the end of the run, the averaged box dimensions are calculated.
138138
"""
139-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
139+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
140+
self.calc.md.cmdargs, self.calc.md.init_commands)
140141

141142
#set up structure
142143
lmp = ph.create_structure(lmp, self.calc, species=self.calc.n_elements+self.calc._ghost_element_count)
@@ -206,7 +207,8 @@ def run_integration(self, iteration=1):
206207
Run the integration routine where the initial and final systems are connected using
207208
the lambda parameter. See algorithm 4 in publication.
208209
"""
209-
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep, self.calc.md.cmdargs)
210+
lmp = ph.create_object(self.cores, self.simfolder, self.calc.md.timestep,
211+
self.calc.md.cmdargs, self.calc.md.init_commands)
210212

211213
#read in the conf file
212214
#conf = os.path.join(self.simfolder, "conf.equilibration.dump")

docs/source/inputfile.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The inputfile is `yaml` formatted. In this section the possible keys in the inpu
2121
| `md` block | | | |
2222
| :------: | :------: | :------: | :------: |
2323
| [](timestep) | [](n_small_steps) | [](n_every_steps) | [](n_repeat_steps) |
24-
| [](n_cycles) | [](thermostat_damping) | [](barostat_damping) |
24+
| [](n_cycles) | [](thermostat_damping) | [](barostat_damping) | [](init_commands) |
2525

2626
| `queue` block | | | |
2727
| :------: | :------: | :------: | :------: |
@@ -128,7 +128,7 @@ Calculation mode. A small description of the different modes are given below.
128128
- `pscale` calculates the free energy as a function of the pressure.
129129

130130
---
131-
131+
self.calc.md.init_commands
132132
(temperature)=
133133
#### `temperature`
134134

@@ -542,6 +542,24 @@ n_cycles: 100
542542

543543
Number of cycles to try converging the pressure of the system. If the pressure is not converged after `n_cycles`, an error will be raised. In each `n_cycle`, `n_small_steps` MD steps will be run.
544544

545+
546+
---
547+
548+
(init_commands)=
549+
#### `init_commands`
550+
551+
_type_: list of strings
552+
_default_: None
553+
_example_:
554+
```
555+
init_commands:
556+
- timestep 0.002
557+
- atom_style charge
558+
- neighbor 0.6 bin
559+
```
560+
561+
Provides the possibility to replace or add initial commands when the LAMMPS object is initialised. If the command is already used in calphy, for example `timestep` or `atom_style` they will be replaced. If it is a new command, it will be added. This commands receive higher priority than the ones that already exist. For examples if you provide `timestep: 0.002` in the `md` block, and `timestep 0.004` in `init_commands`, the timestep used would be 0.004.
562+
545563
---
546564
---
547565

examples/example_01/input.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ md:
1818
timestep: 0.001
1919
thermostat_damping: 0.1
2020
barostat_damping: 0.1
21+
init_commands:
22+
- timestep 0.002
23+
- neighbor 0.6 bin
2124

2225
queue:
2326
scheduler: local

0 commit comments

Comments
 (0)