Skip to content

Commit

Permalink
Merge pull request #56 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Improved handling of trajectories and results
  • Loading branch information
seamm authored Jul 21, 2024
2 parents 8482ec6 + c626bac commit b7bbb90
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 59 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
=======
History
=======
2024.7.21 -- Improved handling of trajectories and results
* Improved control over the trajectories of positions, veloicties, etc. to allow the
user to give the number of points in the trajectory rather than the time interval
of samples
* Added volume of the cell to properties, and the cell lengths, density, and volume
for NVE and NVT, where those parameters don't vary but are nontheless useful in
subsequent analysis.

2024.6.28.1 -- Internal release to fix issue making Docker image.

2024.6.28 -- Added energy and forces to properties
Expand Down
4 changes: 4 additions & 0 deletions lammps_step/data/properties.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Property,Type,Units,Description,URL
"density, stderr#LAMMPS#{model}",float,g/mL,"The standard error of the density.",https://en.wikipedia.org/wiki/Standard_error
"density, tau#LAMMPS#{model}",float,fs,"The autocorrelation time of the density.",https://en.wikipedia.org/wiki/Autocorrelation
"density, inefficiency#LAMMPS#{model}",float,,"The statistical inefficiency of the density sampling.",https://en.wikipedia.org/wiki/Efficiency_(statistics)
"V#LAMMPS#{model}",float,g/mL,"The volume.",https://en.wikipedia.org/wiki/volume
"V, stderr#LAMMPS#{model}",float,g/mL,"The standard error of the volume.",https://en.wikipedia.org/wiki/Standard_error
"V, tau#LAMMPS#{model}",float,fs,"The autocorrelation time of the volume.",https://en.wikipedia.org/wiki/Autocorrelation
"V, inefficiency#LAMMPS#{model}",float,,"The statistical inefficiency of the volume sampling.",https://en.wikipedia.org/wiki/Efficiency_(statistics)
"pressure#LAMMPS#{model}",float,atm,"The pressure.",https://en.wikipedia.org/wiki/Pressure
"pressure, stderr#LAMMPS#{model}",float,atm,"The standard error of the pressure.",https://en.wikipedia.org/wiki/Standard_error
"pressure, tau#LAMMPS#{model}",float,fs,"The autocorrelation time of the pressure.",https://en.wikipedia.org/wiki/Autocorrelation
Expand Down
12 changes: 12 additions & 0 deletions lammps_step/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ def analyze(self, indent="", data={}, table=None, output=[], **kwargs):
# Get the configuration
_, configuration = self.get_system_configuration(None)

# Add static properties such as density for e.g NVE and NVT calculations
if "density" not in data and configuration.periodicity == 3:
data["density"] = configuration.density
if "a" not in data and configuration.periodicity == 3:
data["a"] = configuration.cell.a
if "b" not in data and configuration.periodicity == 3:
data["b"] = configuration.cell.b
if "c" not in data and configuration.periodicity == 3:
data["c"] = configuration.cell.c
if "volume" not in data and configuration.periodicity == 3:
data["volume"] = configuration.cell.volume

# Need to set the model for properties.
# See what type of forcefield we have and handle it
ff = self.get_variable("_forcefield")
Expand Down
62 changes: 57 additions & 5 deletions lammps_step/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@
"units": "",
},
"density": {
"calculation": ["npt"],
"description": "pressure",
"calculation": [
"nve",
"nvt",
"npt",
],
"description": "density",
"dimensionality": "scalar",
"property": "density#LAMMPS#{model}",
"type": "float",
Expand Down Expand Up @@ -150,8 +154,48 @@
"type": "float",
"units": "",
},
"a": {
"V": {
"calculation": [
"nve",
"nvt",
"npt",
],
"description": "V",
"dimensionality": "scalar",
"property": "V#LAMMPS#{model}",
"type": "float",
"units": "g/ml",
},
"V,stderr": {
"calculation": ["npt"],
"description": "stderr of V",
"dimensionality": "scalar",
"property": "V, stderr#LAMMPS#{model}",
"type": "float",
"units": "g/ml",
},
"V,tau": {
"calculation": ["npt"],
"description": "autocorrelation time of V",
"dimensionality": "scalar",
"property": "V, tau#LAMMPS#{model}",
"type": "float",
"units": "fs",
},
"V,inefficiency": {
"calculation": ["npt"],
"description": "statistical inefficiency of V sampling",
"dimensionality": "scalar",
"property": "volume, inefficiency#LAMMPS#{model}",
"type": "float",
"units": "",
},
"a": {
"calculation": [
"nve",
"nvt",
"npt",
],
"description": "cell parameter 'a'",
"dimensionality": "scalar",
"property": "cell_a#LAMMPS#{model}",
Expand Down Expand Up @@ -183,7 +227,11 @@
"units": "",
},
"b": {
"calculation": ["npt"],
"calculation": [
"nve",
"nvt",
"npt",
],
"description": "cell parameter 'b'",
"dimensionality": "scalar",
"property": "cell_b#LAMMPS#{model}",
Expand Down Expand Up @@ -215,7 +263,11 @@
"units": "",
},
"c": {
"calculation": ["npt"],
"calculation": [
"nve",
"nvt",
"npt",
],
"description": "cell parameter 'c'",
"dimensionality": "scalar",
"property": "cell_c#LAMMPS#{model}",
Expand Down
71 changes: 53 additions & 18 deletions lammps_step/nve.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,32 @@ def trajectory_input(self, P, timestep, nsteps, ncomputes, ndumps, nfixes):
The counter for the fixes
"""
lines = []
if P["atomic positions"] != "never":
t_s = lammps_step.to_lammps_units(P["atomic positions"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["atomic positions"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(
P["atomic positions rate"], quantity="time"
)
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["atomic positions number of samples"])
ndumps += 1
filename = f"@{self._id[-1]}+atomic_positions.dump_trj"
lines.append(
"\n"
f"dump {ndumps} all custom {n} {filename} id xu yu zu\n"
f"dump_modify {ndumps} sort id"
)
if P["com positions"] != "never":
t_s = lammps_step.to_lammps_units(P["com positions"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["com positions"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(
P["com positions rate"], quantity="time"
)
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["com positions number of samples"])

filename = f"@{self._id[-1]}+com_positions.trj"
ncomputes += 1
c1 = ncomputes
Expand Down Expand Up @@ -389,19 +402,31 @@ def trajectory_input(self, P, timestep, nsteps, ncomputes, ndumps, nfixes):
f" title3 '{title3}' &\n"
f" file {filename} mode vector"
)
if P["atomic velocities"] != "never":
t_s = lammps_step.to_lammps_units(P["atomic velocities"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["atomic velocities"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(
P["atomic velocities rate"], quantity="time"
)
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["atomic velocities number of samples"])
ndumps += 1
filename = f"@{self._id[-1]}+atomic_velocities.dump_trj"
lines.append(
"\n"
f"dump {ndumps} all custom {n} {filename} id vx vy vz\n"
f"dump_modify {ndumps} sort id"
)
if P["com velocities"] != "never":
t_s = lammps_step.to_lammps_units(P["com velocities"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["com velocities"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(
P["com velocities rate"], quantity="time"
)
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["com velocities number of samples"])
filename = f"@{self._id[-1]}+com_velocities.trj"
ncomputes += 1
c1 = ncomputes
Expand Down Expand Up @@ -432,9 +457,13 @@ def trajectory_input(self, P, timestep, nsteps, ncomputes, ndumps, nfixes):
f" title3 '{title3}' &\n"
f" file {filename} mode vector"
)
if P["heat flux"] != "never":
t_s = lammps_step.to_lammps_units(P["heat flux"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["heat flux"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(P["heat flux rate"], quantity="time")
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["heat flux number of samples"])
filename = f"@{self._id[-1]}+heat_flux.trj"
nfixes += 1
dt = (n * P["timestep"]).to_compact()
Expand All @@ -458,9 +487,15 @@ def trajectory_input(self, P, timestep, nsteps, ncomputes, ndumps, nfixes):
f" title2 '{title2}' &\n"
f" file {filename}"
)
if P["shear stress"] != "never":
t_s = lammps_step.to_lammps_units(P["shear stress"], quantity="time")
n = max(1, round(t_s / timestep))
sampling = P["shear stress"]
if sampling != "never":
if "interval" in sampling:
t_s = lammps_step.to_lammps_units(
P["shear stress rate"], quantity="time"
)
n = max(1, round(t_s / timestep))
else:
n = max(1, nsteps // P["shear stress number of samples"])
filename = f"@{self._id[-1]}+shear_stress.trj"
nfixes += 1
dt = (n * P["timestep"]).to_compact()
Expand Down
Loading

0 comments on commit b7bbb90

Please sign in to comment.