diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fb80418..6cdba0c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -55,7 +55,7 @@ jobs: - name: Build environment run: | conda activate pytest - conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 + conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge python -m pip install --upgrade pip python -m pip install --upgrade setuptools python -m pip install -e '.[dev]' @@ -79,7 +79,7 @@ jobs: - name: Build environment run: | conda activate pytest - conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 + conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge conda install -c conda-forge mdanalysis openbabel python -m pip install --upgrade pip python -m pip install --upgrade setuptools @@ -104,7 +104,7 @@ jobs: - name: Build environment run: | conda activate pytest - conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 + conda install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge conda install -c conda-forge mdanalysis openbabel python -m pip install --upgrade pip python -m pip install --upgrade setuptools diff --git a/README.rst b/README.rst index 804e4bd..8de1d7e 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ Some optional dependencies are only available through conda: # for OpenMM and espaloma charge # note the temporary issue with rdkit versions and conda will overwrite pip # installed software - mamba install openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 + mamba install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge # for xtb mamba install xtb # for openbabel diff --git a/docs/source/index.rst b/docs/source/index.rst index 0aa98e5..3af3921 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -41,7 +41,7 @@ Some optional dependencies are only available through conda: # for OpenMM and espaloma charge # note the temporary issue with rdkit versions and conda will overwrite pip # installed software - mamba install openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 + mamba install -c conda-forge openff-toolkit openmm openmmtools dgl rdkit==2024.3.4 espaloma_charge # for xtb mamba install xtb # for openbabel diff --git a/examples/cage_openmm_example.py b/examples/cage_openmm_example.py index dbde2d7..53eb7bb 100644 --- a/examples/cage_openmm_example.py +++ b/examples/cage_openmm_example.py @@ -44,7 +44,6 @@ def main() -> None: # Settings. force_field = ForceField("openff_unconstrained-2.1.0.offxml") - partial_charges = "espaloma-am1bcc" temperature = 700 * openmm.unit.kelvin friction = 10 / openmm.unit.picoseconds time_step = 1 * openmm.unit.femtoseconds @@ -55,7 +54,7 @@ def main() -> None: stko.OpenMMForceField( force_field=force_field, restricted=True, - partial_charges_method=str(partial_charges), + partial_charges_method="espaloma-am1bcc", ), # Unrestricted optimisation. stko.OpenMMForceField( @@ -63,7 +62,7 @@ def main() -> None: # vacuum calculations (without constraints) force_field=force_field, restricted=False, - partial_charges_method=partial_charges, + partial_charges_method="espaloma-am1bcc", ), # Molecular dynamics, short for equilibration. stko.OpenMMMD( @@ -75,7 +74,7 @@ def main() -> None: time_step=time_step, ), random_seed=275, - partial_charges_method=partial_charges, + partial_charges_method="espaloma-am1bcc", # Frequency here is not related to the num confs tested. reporting_freq=100, trajectory_freq=100, @@ -86,7 +85,7 @@ def main() -> None: conformer_optimiser=stko.OpenMMForceField( force_field=force_field, restricted=False, - partial_charges_method=partial_charges, + partial_charges_method="espaloma-am1bcc", ), ), # Long MD, for collecting lowest energy conformers. @@ -99,7 +98,7 @@ def main() -> None: time_step=time_step, ), random_seed=275, - partial_charges_method=partial_charges, + partial_charges_method="espaloma-am1bcc", # Frequency here is not related to the num confs tested. reporting_freq=100, trajectory_freq=100, @@ -111,7 +110,7 @@ def main() -> None: conformer_optimiser=stko.OpenMMForceField( force_field=force_field, restricted=False, - partial_charges_method=partial_charges, + partial_charges_method="espaloma-am1bcc", ), ), ) diff --git a/justfile b/justfile index 9960e2e..b8f251e 100644 --- a/justfile +++ b/justfile @@ -11,6 +11,11 @@ docs: # Install development environment. dev: pip install -e '.[dev]' + mamba install -y -c conda-forge openff-toolkit openmm openmmtools rdkit==2024.3.4 dgl espaloma_charge + mamba install -y xtb + mamba install -y openbabel + mamba install -y mdanalysis + # Run code checks. check: diff --git a/pyproject.toml b/pyproject.toml index b673b6e..e1cd0a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,11 +11,11 @@ maintainers = [ dependencies = [ # Remove pin once openmm infrastructure is safely moved to >= 2. "numpy < 2", - "rdkit != 2024.3.5", + # Pinned while rdkit changes stk results. + "rdkit == 2024.3.4", "stk", "networkx", "rmsd", - "espaloma-charge", ] requires-python = ">=3.11" dynamic = ["version"] @@ -59,8 +59,6 @@ line-length = 79 [tool.ruff.lint] select = ["ALL"] ignore = [ - "ANN101", - "ANN102", "ANN401", "COM812", "ISC001", @@ -137,5 +135,6 @@ module = [ "openmmforcefields.*", "rmsd.*", "espaloma_charge.*", + "traitlets.*", ] ignore_missing_imports = true diff --git a/src/stko/__init__.py b/src/stko/__init__.py index 8527591..3ca42aa 100644 --- a/src/stko/__init__.py +++ b/src/stko/__init__.py @@ -126,99 +126,99 @@ """Type parameter matching :class:`stk.ConstructedMolecule` or subclasses.""" __all__ = [ - "functional_groups", - "molecule_analysis", - "OrcaExtractor", - "OpenBabelEnergy", - "OrcaEnergy", - "PlanarityCalculator", - "MMFFEnergy", - "UFFEnergy", - "EnergyResults", - "ConstructedMoleculeTorsionResults", - "TorsionResults", - "XTBResults", - "RmsdCalculator", - "RmsdMappedCalculator", - "KabschRmsdCalculator", - "ShapeCalculator", - "OrcaResults", - "PlanarityResults", - "RmsdResults", - "ShapeResults", - "ConstructedMoleculeTorsionCalculator", - "MatchedTorsionCalculator", - "TorsionCalculator", - "XTBExtractor", - "XTBEnergy", - "Du", - "PositionedAtom", - "MDAnalysis", - "ZMatrix", - "MoleculeSplitter", - "MoleculeTransformer", - "Network", - "UnitCell", - "cap_absolute_value", - "get_approximate_cell_size", - "get_from_parameters", - "TopologyExtractor", - "TopologyInfo", - "Torsion", - "TorsionInfo", - "Aligner", - "AlignmentPotential", - "Collapser", - "CollapserMC", - "GulpUFFMDOptimizer", - "GulpUFFOptimizer", - "MacroModelForceField", - "MacroModelMD", - "Optimizer", - "OptimizerSequence", - "OptWriterSequence", - "TryCatchOptimizer", - "NullOptimizer", "ETKDG", "MMFF", "UFF", - "MetalOptimizer", - "MAEExtractor", - "get_metal_atoms", - "move_generated_macromodel_files", - "mol_from_mae_file", "XTB", - "XTBFF", "XTBCREST", + "XTBFF", "XTBFFCREST", + "Aligner", + "AlignmentPotential", + "CalculatorError", + "Collapser", + "CollapserMC", "ConstructedMoleculeT", - "MoleculeT", - "OpenBabel", - "OpenMMForceField", - "OpenMMMD", - "OpenMMEnergy", - "WrapperNotInstalledError", - "DifferentMoleculeError", - "DifferentAtomError", - "InputError", - "PathError", + "ConstructedMoleculeTorsionCalculator", + "ConstructedMoleculeTorsionResults", "ConvergenceError", - "CalculatorError", "ConversionError", + "DifferentAtomError", + "DifferentMoleculeError", + "Du", + "EnergyResults", "ExpectedMetalError", "ForceFieldError", "ForceFieldSetupError", + "GulpUFFMDOptimizer", + "GulpUFFOptimizer", + "InputError", + "InvalidSolventError", + "KabschRmsdCalculator", "LewisStructureError", + "MAEExtractor", + "MDAnalysis", + "MMFFEnergy", + "MacroModelForceField", + "MacroModelMD", + "MatchedTorsionCalculator", + "MetalOptimizer", + "MoleculeSplitter", + "MoleculeT", + "MoleculeTransformer", + "Network", "NotCompletedError", "NotStartedError", - "SettingConflictError", - "InvalidSolventError", + "NullOptimizer", + "OpenBabel", + "OpenBabelEnergy", + "OpenMMEnergy", + "OpenMMForceField", + "OpenMMMD", + "OptWriterSequence", + "Optimizer", "OptimizerError", - "get_torsion_info_angles", + "OptimizerSequence", + "OrcaEnergy", + "OrcaExtractor", + "OrcaResults", + "PathError", + "PlanarityCalculator", + "PlanarityResults", + "PositionedAtom", + "RmsdCalculator", + "RmsdMappedCalculator", + "RmsdResults", + "SettingConflictError", + "ShapeCalculator", + "ShapeResults", + "TopologyExtractor", + "TopologyInfo", + "Torsion", + "TorsionCalculator", + "TorsionInfo", + "TorsionResults", + "TryCatchOptimizer", + "UFFEnergy", + "UnitCell", + "WrapperNotInstalledError", + "XTBEnergy", + "XTBExtractor", + "XTBResults", + "ZMatrix", "calculate_angle", "calculate_dihedral", - "vector_angle", - "unit_vector", - "is_valid_xtb_solvent", + "cap_absolute_value", + "functional_groups", + "get_approximate_cell_size", "get_atom_distance", + "get_from_parameters", + "get_metal_atoms", + "get_torsion_info_angles", + "is_valid_xtb_solvent", + "mol_from_mae_file", + "molecule_analysis", + "move_generated_macromodel_files", + "unit_vector", + "vector_angle", ] diff --git a/src/stko/_internal/molecular/periodic/unitcell.py b/src/stko/_internal/molecular/periodic/unitcell.py index 52a8da7..2922eb4 100644 --- a/src/stko/_internal/molecular/periodic/unitcell.py +++ b/src/stko/_internal/molecular/periodic/unitcell.py @@ -200,10 +200,10 @@ def with_cell_from_cif(self, filename: Path | str) -> Self: with filename.open() as f: lines = f.readlines() - for targ in targets: + for targ, target_string in targets.items(): for line in lines: # Avoid running through the rest. - if targets[targ] in cell_info: + if target_string in cell_info: break splits = line.rstrip().split(" ") if splits[0] == targ: diff --git a/src/stko/_internal/molecular/subgroup_analysis/subgroup_analyser.py b/src/stko/_internal/molecular/subgroup_analysis/subgroup_analyser.py index 10eb405..c583fab 100644 --- a/src/stko/_internal/molecular/subgroup_analysis/subgroup_analyser.py +++ b/src/stko/_internal/molecular/subgroup_analysis/subgroup_analyser.py @@ -222,8 +222,7 @@ def calculate(self, molecule: stk.Molecule) -> dict[str, list[float]]: } fg_results = {} - for pot_fg in fg_definitions: - fg_cls = fg_definitions[pot_fg] + for pot_fg, fg_cls in fg_definitions.items(): fg_results[pot_fg] = fg_cls.measure(molecule) return fg_results diff --git a/src/stko/_internal/optimizers/collapser.py b/src/stko/_internal/optimizers/collapser.py index 56d6264..f89a62e 100644 --- a/src/stko/_internal/optimizers/collapser.py +++ b/src/stko/_internal/optimizers/collapser.py @@ -570,8 +570,7 @@ def _get_cent_to_lb_vector( """Returns dict of long bond atom to bb centroid vectors.""" position_matrix = mol.get_position_matrix() centroid_to_lb_vectors: dict[tuple[int, int], tuple[float]] = {} - for bb in bb_centroids: - cent = bb_centroids[bb] + for bb, cent in bb_centroids.items(): for b_atom_ids in long_bond_infos: for atom_id in b_atom_ids: (atom_info,) = mol.get_atom_infos( # type: ignore[attr-defined] @@ -614,9 +613,7 @@ def _compute_potential( long_bond_infos: dict[tuple[int, int], stk.BondInfo], ) -> float: system_potential = self._compute_non_bonded_potential(mol) - for long_bond_ids in long_bond_infos: - long_bond = long_bond_infos[long_bond_ids] - + for long_bond in long_bond_infos.values(): system_potential += self._bond_potential( distance=self._get_bond_length( mol=mol, diff --git a/src/stko/_internal/optimizers/gulp.py b/src/stko/_internal/optimizers/gulp.py index bc9a571..0419045 100644 --- a/src/stko/_internal/optimizers/gulp.py +++ b/src/stko/_internal/optimizers/gulp.py @@ -477,8 +477,7 @@ def _bond_section( def _species_section(self, type_translator: dict) -> str: species_section = "\nspecies\n" - for spec in type_translator: - name = type_translator[spec] + for spec, name in type_translator.items(): species_section += f"{name} {spec}\n" return species_section @@ -1030,7 +1029,7 @@ def _optimise_all_conformers( low_conf_xyz: Path, ) -> None: min_energy = 1e10 - for ts in trajectory_data: + for ts, ts_data in trajectory_data.items(): if self._save_conformers: conformer_file_name = Path(f"conf_{ts}.xyz") else: @@ -1040,7 +1039,7 @@ def _optimise_all_conformers( self._write_conformer_xyz_file( ts=ts, - ts_data=trajectory_data[ts], + ts_data=ts_data, filename=conformer_file_name, atom_types=atom_types, ) @@ -1069,11 +1068,11 @@ def _save_all_conformers( trajectory_data: dict, atom_types: list[str], ) -> None: - for ts in trajectory_data: + for ts, ts_data in trajectory_data.items(): conformer_file_name = Path(f"conf_{ts}.xyz") self._write_conformer_xyz_file( ts=ts, - ts_data=trajectory_data[ts], + ts_data=ts_data, filename=conformer_file_name, atom_types=atom_types, ) diff --git a/src/stko/functional_groups.py b/src/stko/functional_groups.py index 778de2a..d4f6466 100644 --- a/src/stko/functional_groups.py +++ b/src/stko/functional_groups.py @@ -12,6 +12,6 @@ "CNCFactory", "CNNFactory", "NNNFactory", - "ThreeSiteFactory", "ThreeSiteFG", + "ThreeSiteFactory", ] diff --git a/src/stko/molecule_analysis.py b/src/stko/molecule_analysis.py index 4627265..d1575ea 100644 --- a/src/stko/molecule_analysis.py +++ b/src/stko/molecule_analysis.py @@ -20,13 +20,13 @@ ) __all__ = [ - "GeometryAnalyser", - "ConstructedAnalyser", - "DecomposeMOC", - "DitopicThreeSiteAnalyser", "AlkyneAngle", "C5N1Planarity", "C6Planarity", + "ConstructedAnalyser", + "DecomposeMOC", + "DitopicThreeSiteAnalyser", + "GeometryAnalyser", "Subgroup", "SubgroupAnalyser", "X5Planarity", diff --git a/tests/optimizers/gulp/test_gulp.py b/tests/optimizers/gulp/test_gulp.py index ad73544..3fe7422 100644 --- a/tests/optimizers/gulp/test_gulp.py +++ b/tests/optimizers/gulp/test_gulp.py @@ -178,8 +178,7 @@ def test_gulp_convert_traj_to_xyz( for i, t in zip(atom_types, test_atom_types, strict=False): assert i == t - for ts in trajectory: - test_ts_dict = test_trajectory_data[ts] + for ts, test_ts_dict in trajectory.items(): ts_dict = trajectory[ts] assert test_ts_dict["time"] == ts_dict["time"] assert test_ts_dict["KE"] == ts_dict["KE"]