diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf290d..982f136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `verbosity = 3` always prints full QM output - Adapted generation of number of unpaired electrons; thereby, support for Ln's - Shifted group / element sorting definitions to miscellaneous +- `xyz` files are written on the fly, and not post-generation ### Added - Optimization via DFT in the post-processing step @@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Check for consistency of the `min_num_atoms` and `max_num_atoms` constraint - Similar to the `.CHRG` file, also a `.UHF` is printed - HOMO-LUMO gap check within the refinement step and corresponding Config option called "refine_hlgap" +- `GeneralConfig` switch for writing `xyz` files ## [0.3.0] - 2024-08-20 ### Breaking Changes diff --git a/mindlessgen.toml b/mindlessgen.toml index 605f004..cf1775f 100644 --- a/mindlessgen.toml +++ b/mindlessgen.toml @@ -15,6 +15,8 @@ max_cycles = 100 num_molecules = 1 # > Do post-processing (checking for HL gap, etc.) after the optimization. Options: postprocess = false +# > Switch molecule structure XYZ writing on and off (default: true). Options: +write_xyz = true [generate] # > Minimum number of atoms in the generated molecule. Options: diff --git a/src/mindlessgen/cli/cli_parser.py b/src/mindlessgen/cli/cli_parser.py index a9f0cae..7d8484c 100644 --- a/src/mindlessgen/cli/cli_parser.py +++ b/src/mindlessgen/cli/cli_parser.py @@ -72,6 +72,22 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict: required=False, help="Postprocess the output.", ) + parser.add_argument( + "--write-xyz", + action="store_true", + default=None, + required=False, + help="Write the molecules to xyz files.", + ) + parser.add_argument( + "--no-write-xyz", + action="store_false", + dest="write_xyz", + required=False, + help="Do not write the molecules to xyz files.", + ) + + ### Molecule generation arguments ### parser.add_argument( "--min-num-atoms", type=int, @@ -226,6 +242,7 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict: "print_config": args_dict["print_config"], "num_molecules": args_dict["num_molecules"], "postprocess": args_dict["postprocess"], + "write_xyz": args_dict["write_xyz"], } # Refinement arguments rev_args_dict["refine"] = { diff --git a/src/mindlessgen/cli/entrypoint.py b/src/mindlessgen/cli/entrypoint.py index 0be3a82..53edd3f 100644 --- a/src/mindlessgen/cli/entrypoint.py +++ b/src/mindlessgen/cli/entrypoint.py @@ -45,9 +45,6 @@ def console_entry_point(argv: Sequence[str] | None = None) -> int: if molecules: for molecule in molecules: try: - molecule.write_xyz_to_file() - if config.general.verbosity > 0: - print(f"Written molecule file 'mlm_{molecule.name}.xyz'.") molecules_written.append("mlm_" + molecule.name) except Exception as e: warnings.warn(f"Failed to write molecule file: {e}") diff --git a/src/mindlessgen/generator/main.py b/src/mindlessgen/generator/main.py index b14f920..5bb8826 100644 --- a/src/mindlessgen/generator/main.py +++ b/src/mindlessgen/generator/main.py @@ -124,6 +124,10 @@ def generator(config: ConfigManager) -> tuple[list[Molecule] | None, int]: if config.general.verbosity > 0: print(f"\nOptimized mindless molecule found in {cycles_needed} cycles.") print(optimized_molecule) + if config.general.write_xyz: + optimized_molecule.write_xyz_to_file() + if config.general.verbosity > 0: + print(f"Written molecule file 'mlm_{optimized_molecule.name}.xyz'.") optimized_molecules.append(optimized_molecule) return optimized_molecules, exitcode diff --git a/src/mindlessgen/prog/config.py b/src/mindlessgen/prog/config.py index 84331ae..7727d93 100644 --- a/src/mindlessgen/prog/config.py +++ b/src/mindlessgen/prog/config.py @@ -40,6 +40,7 @@ def __init__(self: GeneralConfig) -> None: self._parallel: int = 1 self._num_molecules: int = 1 self._postprocess: bool = False + self._write_xyz: bool = True def get_identifier(self) -> str: return "general" @@ -148,6 +149,22 @@ def postprocess(self, postprocess: bool): raise TypeError("Postprocess should be a boolean.") self._postprocess = postprocess + @property + def write_xyz(self): + """ + Get the write xyz flag. + """ + return self._write_xyz + + @write_xyz.setter + def write_xyz(self, write_xyz: bool): + """ + Set the write xyz flag. + """ + if not isinstance(write_xyz, bool): + raise TypeError("Write xyz should be a boolean.") + self._write_xyz = write_xyz + class GenerateConfig(BaseConfig): """ diff --git a/test/test_main/test_main.py b/test/test_main/test_main.py index 98d6d31..3bb4855 100644 --- a/test/test_main/test_main.py +++ b/test/test_main/test_main.py @@ -13,6 +13,7 @@ def test_generator(): config.general.parallel = 4 config.general.verbosity = -1 config.general.postprocess = False + config.general.write_xyz = False molecules, exitcode = generator(config) assert exitcode == 0