From 8e279bd925910de8c4c1cc1506f95087a96401dd Mon Sep 17 00:00:00 2001 From: m-julian <52214154+m-julian@users.noreply.github.com> Date: Wed, 24 Apr 2024 23:56:19 +0300 Subject: [PATCH] add parent dir and docstring update --- .../ichor/core/files/xyz/trajectory.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ichor_core_subpackage/ichor/core/files/xyz/trajectory.py b/ichor_core_subpackage/ichor/core/files/xyz/trajectory.py index b1424e62..c670fa71 100644 --- a/ichor_core_subpackage/ichor/core/files/xyz/trajectory.py +++ b/ichor_core_subpackage/ichor/core/files/xyz/trajectory.py @@ -149,7 +149,13 @@ def rmsd(self, ref=None): return [ref.rmsd(point) for point in self] - def to_dir(self, system_name: str, every: int = 1, center=False) -> Path: + def to_dir( + self, + system_name: str, + every: int = 1, + center: bool = False, + parent_dir: Path = None, + ) -> Path: """Writes out every nth timestep to a separate .xyz file to a given directory :param system_name: The name of the system. This will be the name of the @@ -157,6 +163,8 @@ def to_dir(self, system_name: str, every: int = 1, center=False) -> Path: :param every: An integer value that indicates the nth step at which an xyz file should be written. Default is 1. If a value eg. 5 is given, then it will only write out a .xyz file for every 5th timestep. + :param center: Whether or not to subtract mean of coordinates from atomic coordinates, defaults to False + :param parent_dir: A path to a parent directory where the inner directory will be created. :returns: The Path object to the made directory """ @@ -166,7 +174,12 @@ def to_dir(self, system_name: str, every: int = 1, center=False) -> Path: # capitalize system name system_name = system_name.upper() - root_path = Path(system_name).with_suffix(default_root_suffix) + if parent_dir: + if not parent_dir.exists(): + parent_dir.mkdir() + root_path = parent_dir / Path(system_name).with_suffix(default_root_suffix) + else: + root_path = Path(system_name).with_suffix(default_root_suffix) mkdir(root_path, empty=True) for i, atoms_instance in enumerate(self):