Skip to content

Commit 41627ee

Browse files
List outputs (#454)
* Always return absolute filename * Add output files property to calculations * Save output files to CLI summary * Save MD postprocessing filenames * Add output files to missing CLI functions * Fix Mixin tests * Remove duplicate geomopt traj and fix output files * Tidy building filenames * Test output files * Fix saving MD restart files * Fix MD minimize filename * Fix checking lists of output files * Fix MD restart files list * Fix inconsistent paths * Fix local path * Fix docstring * Fix phonon output files * Fix phonon output file tests * Fix writing tuples in CLI summary * Apply suggestions from code review Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> * Update tests/utils.py Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> * Use asserts for tests * Fix when output dir is created * Avoid rebuilding phonon files --------- Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com>
1 parent 09d1a28 commit 41627ee

32 files changed

+962
-271
lines changed

janus_core/calculations/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __init__(
205205
log_suffix,
206206
param_prefix if file_prefix is None else "",
207207
filename=self.log_kwargs["filename"],
208-
).absolute()
208+
)
209209

210210
self.log_kwargs.setdefault("name", calc_name)
211211
self.logger = config_logger(**self.log_kwargs)

janus_core/calculations/descriptors.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,24 @@ def __init__(
183183
check_calculator(image.calc, "get_descriptors")
184184

185185
# Set output file
186-
self.write_kwargs.setdefault("filename", None)
187186
self.write_kwargs["filename"] = self._build_filename(
188-
"descriptors.extxyz", filename=self.write_kwargs["filename"]
189-
).absolute()
187+
"descriptors.extxyz", filename=self.write_kwargs.get("filename")
188+
)
189+
190+
@property
191+
def output_files(self) -> None:
192+
"""
193+
Dictionary of output file labels and paths.
194+
195+
Returns
196+
-------
197+
dict[str, PathLike]
198+
Output file labels and paths.
199+
"""
200+
return {
201+
"log": self.log_kwargs["filename"] if self.logger else None,
202+
"results": self.write_kwargs["filename"] if self.write_results else None,
203+
}
190204

191205
def run(self) -> None:
192206
"""Calculate descriptors for structure(s)."""

janus_core/calculations/eos.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,27 +246,46 @@ def __init__(
246246
if not self.struct.calc:
247247
raise ValueError("Please attach a calculator to `struct`.")
248248

249-
if self.minimize and self.logger:
250-
set_minimize_logging(
251-
self.logger, self.minimize_kwargs, self.log_kwargs, track_carbon
252-
)
249+
set_minimize_logging(
250+
self.logger, self.minimize_kwargs, self.log_kwargs, track_carbon
251+
)
253252

254253
# Set output files
255-
self.write_kwargs.setdefault("filename", None)
256254
self.write_kwargs["filename"] = self._build_filename(
257-
"generated.extxyz", filename=self.write_kwargs["filename"]
258-
).absolute()
255+
"generated.extxyz", filename=self.write_kwargs.get("filename")
256+
)
259257

260-
self.plot_kwargs.setdefault("filename", None)
261258
self.plot_kwargs["filename"] = self._build_filename(
262-
"eos-plot.svg", filename=self.plot_kwargs["filename"]
263-
).absolute()
259+
"eos-plot.svg", filename=self.plot_kwargs.get("filename")
260+
)
261+
self.fit_file = self._build_filename("eos-fit.dat")
262+
self.raw_file = self._build_filename("eos-raw.dat")
264263

265264
self.results = {}
266265
self.volumes = []
267266
self.energies = []
268267
self.lattice_scalars = empty(0)
269268

269+
@property
270+
def output_files(self) -> None:
271+
"""
272+
Dictionary of output file labels and paths.
273+
274+
Returns
275+
-------
276+
dict[str, PathLike]
277+
Output file labels and paths.
278+
"""
279+
return {
280+
"log": self.log_kwargs["filename"] if self.logger else None,
281+
"generated_structures": self.write_kwargs["filename"]
282+
if self.write_structures
283+
else None,
284+
"plot": self.plot_kwargs["filename"] if self.plot_to_file else None,
285+
"fit": self.fit_file if self.write_results else None,
286+
"raw": self.raw_file if self.write_results else None,
287+
}
288+
270289
def run(self) -> EoSResults:
271290
"""
272291
Calculate equation of state.
@@ -302,9 +321,8 @@ def run(self) -> EoSResults:
302321
self._calc_volumes_energies()
303322

304323
if self.write_results:
305-
eos_raw_file = f"{self.file_prefix}-eos-raw.dat"
306-
build_file_dir(eos_raw_file)
307-
with open(eos_raw_file, "w", encoding="utf8") as out:
324+
build_file_dir(self.raw_file)
325+
with open(self.raw_file, "w", encoding="utf8") as out:
308326
print("#Lattice Scalar | Energy [eV] | Volume [Å^3] ", file=out)
309327
for eos_data in zip(
310328
self.lattice_scalars, self.energies, self.volumes, strict=True
@@ -330,9 +348,8 @@ def run(self) -> EoSResults:
330348
self.tracker.stop()
331349

332350
if self.write_results:
333-
eos_fit_file = f"{self.file_prefix}-eos-fit.dat"
334-
build_file_dir(eos_fit_file)
335-
with open(eos_fit_file, "w", encoding="utf8") as out:
351+
build_file_dir(self.fit_file)
352+
with open(self.fit_file, "w", encoding="utf8") as out:
336353
print("#Bulk modulus [GPa] | Energy [eV] | Volume [Å^3] ", file=out)
337354
print(bulk_modulus, e_0, v_0, file=out)
338355

janus_core/calculations/geom_opt.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,53 @@ def __init__(
233233
raise ValueError("Please attach a calculator to `struct`.")
234234

235235
# Set output files
236-
self.write_kwargs.setdefault("filename", None)
237236
self.write_kwargs["filename"] = self._build_filename(
238-
"opt.extxyz", filename=self.write_kwargs["filename"]
239-
).absolute()
237+
"opt.extxyz", filename=self.write_kwargs.get("filename")
238+
)
240239

241240
if self.write_traj:
241+
if "trajectory" in self.opt_kwargs:
242+
raise ValueError(
243+
"Please use traj_kwargs['filename'] to save the trajectory"
244+
)
245+
242246
self.traj_kwargs.setdefault(
243247
"filename", self._build_filename("traj.extxyz").absolute()
244248
)
245-
self.opt_kwargs.setdefault("trajectory", str(self.traj_kwargs["filename"]))
249+
self.opt_kwargs["trajectory"] = str(self.traj_kwargs["filename"])
250+
246251
elif self.traj_kwargs:
247-
raise ValueError("traj_kwargs given, but trajectory writing not enabled.")
252+
raise ValueError(
253+
"traj_kwargs given, but trajectory writing not enabled via write_traj."
254+
)
255+
248256
elif "trajectory" in self.opt_kwargs:
249257
raise ValueError(
250-
'"trajectory" given in opt_kwargs,but trajectory writing not enabled.'
258+
"Please use write_traj, and optionally traj_kwargs['filename'] to "
259+
"save the trajectory"
251260
)
261+
252262
# Configure optimizer dynamics
253263
self.set_optimizer()
254264

265+
@property
266+
def output_files(self) -> None:
267+
"""
268+
Dictionary of output file labels and paths.
269+
270+
Returns
271+
-------
272+
dict[str, PathLike]
273+
Output file labels and paths.
274+
"""
275+
return {
276+
"log": self.log_kwargs["filename"] if self.logger else None,
277+
"optimized_structure": self.write_kwargs["filename"]
278+
if self.write_results
279+
else None,
280+
"trajectory": self.traj_kwargs.get("filename"),
281+
}
282+
255283
def set_optimizer(self) -> None:
256284
"""Set optimizer for geometry optimization."""
257285
self._set_functions()

0 commit comments

Comments
 (0)