Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous xyz file writing #29

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `<basename>.CHRG` file, also a `<basename>.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
Expand Down
2 changes: 2 additions & 0 deletions mindlessgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ max_cycles = 100
num_molecules = 1
# > Do post-processing (checking for HL gap, etc.) after the optimization. Options: <bool>
postprocess = false
# > Switch molecule structure XYZ writing on and off (default: true). Options: <bool>
write_xyz = true

[generate]
# > Minimum number of atoms in the generated molecule. Options: <int>
Expand Down
17 changes: 17 additions & 0 deletions src/mindlessgen/cli/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"] = {
Expand Down
3 changes: 0 additions & 3 deletions src/mindlessgen/cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
jonathan-schoeps marked this conversation as resolved.
Show resolved Hide resolved
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}")
Expand Down
4 changes: 4 additions & 0 deletions src/mindlessgen/generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/mindlessgen/prog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions test/test_main/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down