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

Dev/sym opt #111

Merged
merged 26 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f6a3282
Interface for the qm program turbomole
jonathan-schoeps Dec 18, 2024
d6c60c2
support for turbomole
jonathan-schoeps Jan 8, 2025
eefcb3f
Merge branch 'main' into dev/tm_interface
jonathan-schoeps Jan 8, 2025
0a20340
corrected some typos
jonathan-schoeps Jan 8, 2025
e4f79b7
structure_mod baseline
jonathan-schoeps Jan 10, 2025
44cec38
Merge branch 'main' into dev/symmetrie_operations
jonathan-schoeps Jan 10, 2025
a1f9716
baseline for the symmetrie class
jonathan-schoeps Jan 10, 2025
144e309
Implementation of the structur modification module containing Cn rota…
jonathan-schoeps Jan 17, 2025
6e2c63f
merged recent changes
jonathan-schoeps Jan 21, 2025
e5513ec
update to the structure_modification routine and implemented unit tests.
jonathan-schoeps Jan 22, 2025
7d0e5b2
removal of left over dead code snippets
jonathan-schoeps Jan 22, 2025
6c099b0
changed a typo in the change log
jonathan-schoeps Jan 23, 2025
245c915
Re structerization of Structure_modification
jonathan-schoeps Jan 24, 2025
90fad3e
Merge branch 'main' into dev/sym_opt
jonathan-schoeps Jan 24, 2025
36cb528
bug fixes to get the structure mod classes working
jonathan-schoeps Jan 27, 2025
a7ae337
changed a word in mindlessgen.toml
jonathan-schoeps Jan 27, 2025
c7b1bf3
reorganize translation and initialization
marcelmbn Jan 27, 2025
09c6f73
refactored object-orientation of structure modification classes; fixe…
marcelmbn Jan 27, 2025
a6b61d5
abstract structure merge; minor revisions for config
marcelmbn Jan 28, 2025
d5b5fc8
Fix to print the correct output of tm and remove of a redundant singl…
jonathan-schoeps Jan 28, 2025
f7599c8
distance check for clashes and iterative distance increase if too low
marcelmbn Jan 28, 2025
76b06ff
rename some file and Class names to typical conventions
marcelmbn Jan 28, 2025
2fe6b50
further variable renaming; config clean-up
marcelmbn Jan 28, 2025
4b25ca4
add CLI access for arguments and minor adaptions
marcelmbn Jan 28, 2025
3354eac
update default TOML file
marcelmbn Jan 28, 2025
379b6ab
some renamings, better docstrings, remove useless variable copies
marcelmbn Jan 28, 2025
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `GXTBConfig` class for the g-xTB method, supporting SCF cycles check
- support for TURBOMOLE as QM engine.
- support for TURBOMOLE as QM engine
- updated the parallelization to work over the number of molecules
- possibility to generate symmetrical molecules (choice from rotation, inversion, mirroring)

### Fixed
- version string is now correctly formatted and printed
Expand Down
15 changes: 12 additions & 3 deletions mindlessgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# > Verbosity level defining the printout: Options: -1 = super-silent, 0 = silent, 1 = default, 2 = verbose, 3 = debug
verbosity = 1
# > Number of parallel processes to use. Corresponds to the number of physical CPU cores used. Options: <int>
parallel = 1
parallel = 4
# > Maximum number of generation & optimization try-and-error cycles per molecule. Options: <int>
max_cycles = 200
# > Number of molecules to generate. Options: <int>
Expand All @@ -17,6 +17,9 @@ num_molecules = 1
postprocess = false
# > Switch molecule structure XYZ writing on and off. Default: true. Options: <bool>
write_xyz = true
# > Switch generation of symmetrical molecules consisting of substructures on and off. Defaul: false. Options: <bool>
# > Postprocessing is recommended. Choosing "TURBOMOLE" as postprocessing engine is recommended due to symmetry handling.
symmetrization = false

[generate]
# > Minimum number of atoms in the generated molecule. Options: <int>
Expand Down Expand Up @@ -59,7 +62,7 @@ hlgap = 0.5
# > If `debug` is true, the process is terminated after the first (successful or not) refinement step.
debug = false
# > Number of cores to be used for geometry optimizations. Single-points will continue to use one core each.
ncores = 4
ncores = 2

[postprocess]
# > Engine for the post-processing part. Options: 'xtb', 'orca', 'turbomole'
Expand All @@ -73,7 +76,7 @@ opt_cycles = 5
# > Note: This option is only relevant if the 'postprocess' option in the 'general' section is set to 'true'.
debug = false
# > Number of cores to be used for both single-point calculations and geometry optimizations.
ncores = 4
ncores = 2

[xtb]
# > Path to the xtb executable. The names `xtb` and `xtb_dev` are automatically searched for. Options: <str | Path>
Expand Down Expand Up @@ -104,3 +107,9 @@ functional = "PBE"
basis = "def2-SVP"
# > Maximum number of SCF cycles: Options: <int>
scf_cycles = 100

[symmetrization]
# > Distance of the symmetric sub-structures on the translation axis (x). Options: <float>
distance = 3.0
# > Only one symmetry operation at a time can be chosen. Options: <mirror>, <inversion> and <c_<n>_rotation>. For n Options: <int>.
operation = "mirror"
53 changes: 42 additions & 11 deletions src/mindlessgen/cli/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,11 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
help="Do not write the molecules to xyz files.",
)
parser.add_argument(
"--scale-fragment-detection",
type=float,
required=False,
help="Scaling factor for the fragment detection based on the van der Waals radii.",
)
parser.add_argument(
"--scale-minimal-distance",
type=float,
"--symmetrization",
action="store_true",
default=None,
required=False,
help="Minimum atom distance scaling factor.",
help="Generate symmetric MLM complexes.",
)

### Molecule generation arguments ###
Expand Down Expand Up @@ -125,6 +120,18 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
help="Factor with which the coordinate scaling factor is increased "
+ "after a failed attempt.",
)
parser.add_argument(
"--scale-fragment-detection",
type=float,
required=False,
help="Scaling factor for the fragment detection based on the van der Waals radii.",
)
parser.add_argument(
"--scale-minimal-distance",
type=float,
required=False,
help="Minimum atom distance scaling factor.",
)
parser.add_argument(
"--element-composition",
type=str,
Expand Down Expand Up @@ -271,6 +278,22 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
required=False,
help="Maximum number of SCF cycles in g-xTB.",
)

### Symmetrization specific arguments ###
parser.add_argument(
"--symmetrization-distance",
type=float,
required=False,
help="Define the distance of the symmetric fragments.",
)
parser.add_argument(
"--symmetry-operation",
type=str,
required=False,
help="Define the symmetry operation to use.",
)

### Parse arguments ###
args = parser.parse_args(argv)
args_dict = vars(args)

Expand All @@ -286,6 +309,7 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
"num_molecules": args_dict["num_molecules"],
"postprocess": args_dict["postprocess"],
"write_xyz": args_dict["write_xyz"],
"symmetrization": args_dict["symmetrization"],
}
# Refinement arguments
rev_args_dict["refine"] = {
Expand All @@ -309,8 +333,10 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
"fixed_composition": args_dict["fixed_composition"],
}
# XTB specific arguments
rev_args_dict["xtb"] = {"xtb_path": args_dict["xtb_path"]}
rev_args_dict["xtb"]["level"] = args_dict["xtb_level"]
rev_args_dict["xtb"] = {
"xtb_path": args_dict["xtb_path"],
"level": args_dict["xtb_level"],
}
# ORCA specific arguments
rev_args_dict["orca"] = {
"orca_path": args_dict["orca_path"],
Expand All @@ -331,5 +357,10 @@ def cli_parser(argv: Sequence[str] | None = None) -> dict:
"opt_cycles": args_dict["postprocess_opt_cycles"],
"debug": args_dict["postprocess_debug"],
}
# Symmetrization specific arguments
rev_args_dict["symmetrization"] = {
"distance": args_dict["symmetrization_distance"],
"operation": args_dict["symmetry_operation"],
}

return rev_args_dict
53 changes: 52 additions & 1 deletion src/mindlessgen/generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@
get_gxtb_path,
)
from ..molecules import iterative_optimization, postprocess_mol
from ..prog import ConfigManager, setup_managers, ResourceMonitor, setup_blocks
from ..prog import (
ConfigManager,
SymmetrizationConfig,
setup_managers,
ResourceMonitor,
setup_blocks,
)
from ..symmetrization import (
Symmetrizer,
CnRotation,
Mirror,
Inversion,
)
from ..__version__ import __version__

MINDLESS_MOLECULES_FILE = "mindless.molecules"
Expand Down Expand Up @@ -71,6 +83,13 @@ def generator(config: ConfigManager) -> tuple[list[Molecule], int]:
get_jobex_path,
)

if config.general.symmetrization:
structure_mod_model: Symmetrizer | None = setup_structure_modification_model(
config.symmetrization.operation, config.symmetrization
)
else:
structure_mod_model = None

if config.general.postprocess:
postprocess_engine: QMMethod | None = setup_engines(
config.postprocess.engine,
Expand Down Expand Up @@ -137,6 +156,7 @@ def generator(config: ConfigManager) -> tuple[list[Molecule], int]:
resources,
refine_engine,
postprocess_engine,
structure_mod_model,
block.ncores,
)
)
Expand Down Expand Up @@ -181,6 +201,7 @@ def single_molecule_generator(
resources: ResourceMonitor,
refine_engine: QMMethod,
postprocess_engine: QMMethod | None,
structure_mod_model: Symmetrizer,
ncores: int,
) -> Molecule | None:
"""
Expand Down Expand Up @@ -211,6 +232,7 @@ def single_molecule_generator(
resources_local,
refine_engine,
postprocess_engine,
structure_mod_model,
cycle,
stop_event,
)
Expand Down Expand Up @@ -250,6 +272,7 @@ def single_molecule_step(
resources_local: ResourceMonitor,
refine_engine: QMMethod,
postprocess_engine: QMMethod | None,
structure_mod_model: Symmetrizer,
cycle: int,
stop_event: Event,
) -> Molecule | None:
Expand Down Expand Up @@ -315,6 +338,18 @@ def single_molecule_step(
if config.refine.debug:
stop_event.set()

if config.general.symmetrization:
try:
optimized_molecule = structure_mod_model.get_symmetric_structure(
optimized_molecule,
)
except RuntimeError as e:
if config.general.verbosity > 0:
print(f"Structure modification failed for cycle {cycle + 1}.")
if config.general.verbosity > 1:
print(e)
return None

if config.general.postprocess:
try:
optimized_molecule = postprocess_mol(
Expand Down Expand Up @@ -422,3 +457,19 @@ def setup_engines(
return GXTB(path, cfg.gxtb)
else:
raise NotImplementedError("Engine not implemented.")


def setup_structure_modification_model(
structure_mod_type: str, config: SymmetrizationConfig
) -> Symmetrizer:
"""
Set up the structure modification model.
"""
# TODO: Enable the use of more than one structure modification model at a time
if structure_mod_type.endswith("rotation"):
return CnRotation(config)
if structure_mod_type == "mirror":
return Mirror(config)
if structure_mod_type == "inversion":
return Inversion(config)
raise NotImplementedError("Structure modification not implemented.")
2 changes: 2 additions & 0 deletions src/mindlessgen/prog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
GenerateConfig,
RefineConfig,
PostProcessConfig,
SymmetrizationConfig,
)
from .parallel import setup_managers, ResourceMonitor, setup_blocks

Expand All @@ -29,4 +30,5 @@
"setup_managers",
"ResourceMonitor",
"setup_blocks",
"SymmetrizationConfig",
]
Loading