abmptools 2.19.2__tar.gz → 2.20.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abmptools-2.19.2/abmptools.egg-info → abmptools-2.20.0}/PKG-INFO +2 -2
- {abmptools-2.19.2 → abmptools-2.20.0}/README.md +1 -1
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/__init__.py +4 -0
- abmptools-2.20.0/abmptools/_version.py +40 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/core/system_model.py +17 -0
- abmptools-2.20.0/abmptools/gro2udf/angle_table.py +136 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/cli.py +39 -9
- abmptools-2.20.0/abmptools/gro2udf/ff_detect.py +229 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/guard.py +157 -20
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/mdp_parser.py +41 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/top_adapter.py +26 -1
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/top_exporter.py +400 -50
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/top_model.py +38 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/top_parser.py +351 -25
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/trajectory/postprocess.py +3 -1
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/top_writer.py +38 -6
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/udf_adapter.py +244 -13
- {abmptools-2.19.2 → abmptools-2.20.0/abmptools.egg-info}/PKG-INFO +2 -2
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools.egg-info/SOURCES.txt +9 -1
- {abmptools-2.19.2 → abmptools-2.20.0}/pyproject.toml +1 -1
- abmptools-2.20.0/tests/test_gro2udf_angle_table.py +539 -0
- abmptools-2.20.0/tests/test_gro2udf_coarse_grained.py +162 -0
- abmptools-2.20.0/tests/test_gro2udf_ff_auto.py +143 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_guard.py +36 -22
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_regression.py +6 -1
- abmptools-2.20.0/tests/test_top_exporter_pressure_dc.py +44 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_parser.py +86 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_trajectory_gen_for_udf.py +16 -0
- abmptools-2.20.0/tests/test_udf2gro_cognac_ff.py +160 -0
- abmptools-2.20.0/tests/test_version_attr.py +53 -0
- abmptools-2.19.2/tests/test_top_exporter_pressure_dc.py +0 -45
- {abmptools-2.19.2 → abmptools-2.20.0}/LICENSE +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/NOTICE +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/abinit_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/addsolvfrag.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/ajf2config.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/ajfserial.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/__main__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/builder.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/cli.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/density.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/mdp_protocol.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/models.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/molecule_prep.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/ndx_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/packing.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/parameterizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/pubchem.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/system_model_adapter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/amorphous/trajectory_ingest.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/anlfmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/convertcpf.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/core/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/core/_subprocess.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/core/acpype.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/core/top_atomtypes.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/cpf2ifielist.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/cpfmanager.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/generate_difie.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/generateajf.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/geomopt/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/geomopt/mace_optimizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/geomopt/openff_openmm_minimizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/geomopt/pyscf_optimizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/getcharge.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/getifiepieda.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/__main__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/default_template.udf +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/default_template_cognac101.udf +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/exporter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/gro_adapter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/gro_parser.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/make_whole.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/molecule_select.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/trajectory_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/gro2udf/udf_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/log2config.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/log2cpf.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/logmanager.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/mol_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/molcalc.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/pdb2fmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/pdb_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/pdbmodify.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/readcif.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/setfmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/trajectory/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/trajectory/__main__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/trajectory/cli.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2fmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/__main__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/cli.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/exporter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/_validator.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/gro_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/itp_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf2gro/gromacs/writers/mdp_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udf_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfcharge/__init__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfcharge/__main__.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfcharge/core.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfcreate.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfcreate_v2.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools/udfrm_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools.egg-info/dependency_links.txt +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools.egg-info/entry_points.txt +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools.egg-info/requires.txt +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/abmptools.egg-info/top_level.txt +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/setup.cfg +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/setup.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_abinit_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_ajf_section_headers.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_amorphous_charges_from_file.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_amorphous_models.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_amorphous_molecule_prep.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_anlfmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_builder_integration.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_builder_mocked.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_charge_method.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_citation_version.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_cli_scripts.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_console_output_cp932.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_cpfmanager.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_density.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_enhanced_pieda.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_getifiepieda.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_atom_identity.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_constraints_as_bonds.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_encoding.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_frame_thinning.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_keep_molecules.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_make_whole.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_nose_hoover.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_potential_names.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_torsion_scaling.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro2udf_type_name_collision.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro_adapter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro_parser.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_gro_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_ifie_methods.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_interchange_adapter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_logmanager.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_md_fmo_resume.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_mdp_parser.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_mdp_protocol.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_mdp_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_mol_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_molcalc.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_ndx_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_parameterizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_pdb_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_pubchem.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_pyscf_optimizer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_pyscf_parsers.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_read_ifie_hf_fallback.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_readcif.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_setfmo.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_system_model.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_system_model_extensions.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_adapter_torsion_index.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_atomtypes_element.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_deformation_none.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_display_type.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_energy_alignment.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_frames_override.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_static_cell.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_exporter_static_structure.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_fold_atomtypes.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_model.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_top_writer.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_trajectory_ingest.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_trajectory_postprocess.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udf2gro_molname_helpers.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udf2gro_multiterm_dihedrals.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udf2gro_thermostat_barostat.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udf2gro_unit_parameter.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udf_io.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udfcreate.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udfcreate_v2.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udfcreate_v2_byte_equivalence.py +0 -0
- {abmptools-2.19.2 → abmptools-2.20.0}/tests/test_udfrm_io.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: abmptools
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.20.0
|
|
4
4
|
Summary: Pre/post-processing and analysis toolkit for ABINIT-MP Fragment Molecular Orbital calculations
|
|
5
5
|
Author: Koji Okuwaki
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -86,7 +86,7 @@ A Python toolkit for pre-processing, post-processing, and analysis of Fragment M
|
|
|
86
86
|
### GROMACS ↔ OCTA COGNAC Conversion
|
|
87
87
|
|
|
88
88
|
- **udf2gro**: Convert OCTA UDF files to GROMACS format (`.gro`, `.top`, `.mdp`, `.itp`)
|
|
89
|
-
- **gro2udf**: Convert GROMACS files to OCTA UDF format (supports `--from-top` mode)
|
|
89
|
+
- **gro2udf**: Convert GROMACS files to OCTA UDF format (supports `--from-top` mode; `--for-viewing` writes a file meant to be looked at rather than run, leaving out the terms the engine cannot hold and saying which)
|
|
90
90
|
- **udfcharge**: Transfer per-atom partial charges from a single-molecule UDF to bulk molecules (`transfer`), or restore a neutralized UDF's charges to a target integer formal charge (`restore`)
|
|
91
91
|
|
|
92
92
|
### Geometry Optimization (`geomopt`)
|
|
@@ -36,7 +36,7 @@ A Python toolkit for pre-processing, post-processing, and analysis of Fragment M
|
|
|
36
36
|
### GROMACS ↔ OCTA COGNAC Conversion
|
|
37
37
|
|
|
38
38
|
- **udf2gro**: Convert OCTA UDF files to GROMACS format (`.gro`, `.top`, `.mdp`, `.itp`)
|
|
39
|
-
- **gro2udf**: Convert GROMACS files to OCTA UDF format (supports `--from-top` mode)
|
|
39
|
+
- **gro2udf**: Convert GROMACS files to OCTA UDF format (supports `--from-top` mode; `--for-viewing` writes a file meant to be looked at rather than run, leaving out the terms the engine cannot hold and saying which)
|
|
40
40
|
- **udfcharge**: Transfer per-atom partial charges from a single-molecule UDF to bulk molecules (`transfer`), or restore a neutralized UDF's charges to a target integer formal charge (`restore`)
|
|
41
41
|
|
|
42
42
|
### Geometry Optimization (`geomopt`)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""``abmptools.__version__``.
|
|
3
|
+
|
|
4
|
+
The version is declared once, in ``pyproject.toml``; an installed wheel carries
|
|
5
|
+
it in its metadata, so that is where it is read from. A source checkout is the
|
|
6
|
+
exception: an editable install keeps the metadata written when it was
|
|
7
|
+
installed, and after a version bump ``importlib.metadata`` goes on reporting
|
|
8
|
+
the old number (seen: 2.9.0 from a 2.19 tree). When the package is imported
|
|
9
|
+
from a tree that has its ``pyproject.toml`` next to it, that file is read
|
|
10
|
+
instead.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import pathlib
|
|
15
|
+
import re
|
|
16
|
+
from importlib import metadata
|
|
17
|
+
|
|
18
|
+
UNKNOWN = "0+unknown"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _from_source_tree(pkg_dir: pathlib.Path):
|
|
22
|
+
pyproject = pkg_dir.parent / "pyproject.toml"
|
|
23
|
+
try:
|
|
24
|
+
text = pyproject.read_text(encoding="utf-8")
|
|
25
|
+
except OSError:
|
|
26
|
+
return None
|
|
27
|
+
if not re.search(r'^name = "abmptools"', text, re.M):
|
|
28
|
+
return None
|
|
29
|
+
m = re.search(r'^version = "([^"]+)"', text, re.M)
|
|
30
|
+
return m.group(1) if m else None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_version(pkg_dir: pathlib.Path = pathlib.Path(__file__).resolve().parent) -> str:
|
|
34
|
+
v = _from_source_tree(pkg_dir)
|
|
35
|
+
if v:
|
|
36
|
+
return v
|
|
37
|
+
try:
|
|
38
|
+
return metadata.version("abmptools")
|
|
39
|
+
except metadata.PackageNotFoundError:
|
|
40
|
+
return UNKNOWN
|
|
@@ -82,6 +82,10 @@ class AtomRecord:
|
|
|
82
82
|
type_name: str # force-field atom type (e.g. "ca")
|
|
83
83
|
gro_name: str # name in gro/top atom column (first2 chars + hex index)
|
|
84
84
|
charge: float # [e]
|
|
85
|
+
#: Residue of the atom, when the source has residues (a protein). None
|
|
86
|
+
#: keeps the old [ atoms ] columns: residue 1, named after the molecule.
|
|
87
|
+
resnr: Optional[int] = None
|
|
88
|
+
resname: Optional[str] = None
|
|
85
89
|
|
|
86
90
|
|
|
87
91
|
@dataclass
|
|
@@ -143,6 +147,10 @@ class MoleculeTopology:
|
|
|
143
147
|
pairs: List[PairRecord] = field(default_factory=list)
|
|
144
148
|
angles: List[AngleRecord] = field(default_factory=list)
|
|
145
149
|
dihedrals: List[DihedralRecord] = field(default_factory=list)
|
|
150
|
+
#: Rigid 3-site water: ``(d_OH, d_HH)`` [nm] for [ settles ]. The first
|
|
151
|
+
#: atom must be the oxygen. The writer then also excludes the three
|
|
152
|
+
#: atoms from each other ([ exclusions ]).
|
|
153
|
+
settles: Optional[Tuple[float, float]] = None
|
|
146
154
|
|
|
147
155
|
|
|
148
156
|
# ---------------------------------------------------------------------------
|
|
@@ -415,3 +423,12 @@ class SystemModel:
|
|
|
415
423
|
# The writer layer checks this; adapters set it via
|
|
416
424
|
# :func:`classify_ensemble` when building the SystemModel.
|
|
417
425
|
ensemble_family: str = "gromacs_ok"
|
|
426
|
+
|
|
427
|
+
# --- non-bonded rows beyond the combination rule ----------------------
|
|
428
|
+
#: ``(type1, type2, sigma [nm], epsilon [kJ/mol])`` for a pair the
|
|
429
|
+
#: combination rule does not reproduce ([ nonbond_params ]).
|
|
430
|
+
nonbond_params: List[Tuple[str, str, float, float]] = field(default_factory=list)
|
|
431
|
+
#: ``(type1, type2, sigma [nm], epsilon [kJ/mol])`` for a 1-4 pair whose
|
|
432
|
+
#: scale differs from ``fudgeLJ``; epsilon is already scaled
|
|
433
|
+
#: ([ pairtypes ]).
|
|
434
|
+
pair_types: List[Tuple[str, str, float, float]] = field(default_factory=list)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Write an angle potential that has no closed form as a numerical table.
|
|
3
|
+
|
|
4
|
+
Restricted bending (GROMACS angle funct 10) is
|
|
5
|
+
|
|
6
|
+
V(t) = k/2 (cos t - cos t0)^2 / sin^2 t
|
|
7
|
+
|
|
8
|
+
and the engine has no such function. It does take a **table**, read as a
|
|
9
|
+
function of one variable, and that reproduces the potential to whatever
|
|
10
|
+
accuracy the mesh is given -- this is not an approximation of the form, only
|
|
11
|
+
of the sampling, and the sampling error is measured in the tests.
|
|
12
|
+
|
|
13
|
+
Two conventions matter and both are read off the engine's own source
|
|
14
|
+
(``src/tableangle.cpp``):
|
|
15
|
+
|
|
16
|
+
* the table variable is ``cos`` of the **exterior** angle,
|
|
17
|
+
``var = dr0 . dr1 / |dr0||dr1|``, which is ``-cos t`` of the interior angle
|
|
18
|
+
GROMACS uses -- the same supplement that bonded angles already follow;
|
|
19
|
+
* the values are energies in the file's own energy unit.
|
|
20
|
+
|
|
21
|
+
The table file is a small UDF of its own (``Mesh`` + ``FieldValue`` +
|
|
22
|
+
``Unit_Parameter``), the layout the engine ships as
|
|
23
|
+
``sample/tablepotential/angle_table.udf``.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import logging
|
|
28
|
+
import math
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from typing import List, Optional, Sequence
|
|
31
|
+
|
|
32
|
+
logger = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
__all__ = ["RESTRICTED_BENDING", "reb_energy", "table_values", "write_angle_table"]
|
|
35
|
+
|
|
36
|
+
#: GROMACS angle funct for restricted bending.
|
|
37
|
+
RESTRICTED_BENDING = 10
|
|
38
|
+
|
|
39
|
+
#: Divisions of the ``cos`` axis. 2000 puts the points 0.001 apart, which
|
|
40
|
+
#: keeps the interpolation error below a thousandth of a kJ/mol away from
|
|
41
|
+
#: the ends (``tests/test_gro2udf_angle_table.py`` measures it).
|
|
42
|
+
DEFAULT_DIVISIONS = 2000
|
|
43
|
+
|
|
44
|
+
#: The potential diverges where ``sin t`` reaches zero, so the two end points
|
|
45
|
+
#: are written at this value instead of infinity. It is far above anything a
|
|
46
|
+
#: simulation reaches, and the engine never needs a force there because the
|
|
47
|
+
#: geometry cannot get past it.
|
|
48
|
+
END_VALUE_KJ = 1.0e6
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def reb_energy(var: float, k: float, theta0_deg: float) -> float:
|
|
52
|
+
"""Restricted bending at ``var = cos(exterior angle)`` [kJ/mol].
|
|
53
|
+
|
|
54
|
+
*k* is the force constant from the topology [kJ/mol] and *theta0_deg* the
|
|
55
|
+
equilibrium angle in GROMACS' (interior) convention.
|
|
56
|
+
"""
|
|
57
|
+
sin2 = 1.0 - var * var
|
|
58
|
+
if sin2 <= 1.0e-12:
|
|
59
|
+
return END_VALUE_KJ
|
|
60
|
+
cos_t = -var # interior angle
|
|
61
|
+
cos_t0 = math.cos(math.radians(theta0_deg))
|
|
62
|
+
value = 0.5 * k * (cos_t - cos_t0) ** 2 / sin2
|
|
63
|
+
return min(value, END_VALUE_KJ)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def table_values(k: float, theta0_deg: float,
|
|
67
|
+
divisions: int = DEFAULT_DIVISIONS) -> List[float]:
|
|
68
|
+
"""The ``divisions + 1`` energies [kJ/mol] over ``var`` from -1 to 1."""
|
|
69
|
+
step = 2.0 / divisions
|
|
70
|
+
return [reb_energy(-1.0 + i * step, k, theta0_deg)
|
|
71
|
+
for i in range(divisions + 1)]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def write_angle_table(path: Path, name: str, k: float, theta0_deg: float,
|
|
75
|
+
energy_unit_kj: float = 4.184,
|
|
76
|
+
mass_unit_amu: float = 1.0,
|
|
77
|
+
length_unit_nm: float = 0.1,
|
|
78
|
+
divisions: int = DEFAULT_DIVISIONS) -> Path:
|
|
79
|
+
"""Write one table UDF and return its path.
|
|
80
|
+
|
|
81
|
+
*energy_unit_kj* must be the same unit the main UDF uses, because the
|
|
82
|
+
values are written in it.
|
|
83
|
+
"""
|
|
84
|
+
path = Path(path)
|
|
85
|
+
values = table_values(k, theta0_deg, divisions)
|
|
86
|
+
rows = "\n".join(" {:.8g}".format(v / energy_unit_kj) for v in values)
|
|
87
|
+
head = [
|
|
88
|
+
"Table Potential FOR COGNAC",
|
|
89
|
+
'\\include{"cognac_unit.udf"}',
|
|
90
|
+
"\\begin{def}",
|
|
91
|
+
"class MeshAxis:{",
|
|
92
|
+
'\tvalues[]:double\t"Parameter of axis. [0]:min, [1]:max, [2]:divisions"',
|
|
93
|
+
"}",
|
|
94
|
+
"Mesh:{",
|
|
95
|
+
'\tname:KEY\t"Name of mesh"',
|
|
96
|
+
'\ttype:string\t"Type of mesh. Always \'Regular\' in COGNAC"',
|
|
97
|
+
'\taxes[]:MeshAxis\t"Array of the parameter for each axis"',
|
|
98
|
+
"}",
|
|
99
|
+
"FieldValue: {",
|
|
100
|
+
' values[]:double\t[epsilon]\t"Field data"',
|
|
101
|
+
"}",
|
|
102
|
+
"Unit_Parameter:{",
|
|
103
|
+
'\tName: string\t"Name"',
|
|
104
|
+
'\tComment:string\t"Comment"',
|
|
105
|
+
'\tMass:double\t[amu]\t"Unit mass (atomic mass unit)"',
|
|
106
|
+
'\tEnergy:double\t[kJ/mol]\t"Unit energy(kJ/mol)"',
|
|
107
|
+
'\tLength:double\t[nm]\t"Unit length(nm)"',
|
|
108
|
+
'} "Parameters for unit conversion"',
|
|
109
|
+
"\\end{def}",
|
|
110
|
+
"",
|
|
111
|
+
"\\begin{data}",
|
|
112
|
+
"",
|
|
113
|
+
"Mesh:{",
|
|
114
|
+
'\tname "{}"'.format(name),
|
|
115
|
+
'\ttype "REGULAR"',
|
|
116
|
+
"\t[ devision",
|
|
117
|
+
"\t{{ [ -1.0 1.0 {} ] }}".format(divisions),
|
|
118
|
+
"\t]",
|
|
119
|
+
"}",
|
|
120
|
+
"",
|
|
121
|
+
"FieldValue:{",
|
|
122
|
+
"\t[ value",
|
|
123
|
+
rows,
|
|
124
|
+
"\t]",
|
|
125
|
+
"}",
|
|
126
|
+
"",
|
|
127
|
+
'Unit_Parameter:{{"{}" "restricted bending, written by gro2udf" '
|
|
128
|
+
"{:g} {:g} {:g} }}".format(name, mass_unit_amu, energy_unit_kj,
|
|
129
|
+
length_unit_nm),
|
|
130
|
+
"\\end{data}",
|
|
131
|
+
"",
|
|
132
|
+
]
|
|
133
|
+
path.write_text("\n".join(head), encoding="utf-8", newline="\n")
|
|
134
|
+
logger.info("angle table written: %s (%d points, k = %g, theta0 = %g)",
|
|
135
|
+
path, divisions + 1, k, theta0_deg)
|
|
136
|
+
return path
|
|
@@ -74,15 +74,18 @@ def _from_top_parser():
|
|
|
74
74
|
"and reproduces its output exactly. The "
|
|
75
75
|
"difference in Q is 0.03%% at 3050 atoms and "
|
|
76
76
|
"0.6%% at 80.")
|
|
77
|
-
parser.add_argument("--ff", dest="force_field", default="
|
|
77
|
+
parser.add_argument("--ff", dest="force_field", default="auto",
|
|
78
78
|
help="Force field to declare in Unit_Parameter.Comment "
|
|
79
|
-
"as FF=n, where downstream converters read it.
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
79
|
+
"as FF=n, where downstream converters read it. "
|
|
80
|
+
"auto (default) names it from the topology: its "
|
|
81
|
+
"#include names, its atom types (GAFF and GAFF2 told "
|
|
82
|
+
"apart by their Lennard-Jones values) and [ defaults ]; "
|
|
83
|
+
"when no single force field fits (two of them, or no "
|
|
84
|
+
"evidence) nothing is written and the reason is "
|
|
85
|
+
"printed. Or name it: gaff, gaff2, amber, amber20, "
|
|
86
|
+
"dreiding, uff, oplsaa, loplsaa, loplsaa2023, pcff, "
|
|
87
|
+
"a bare number, or '' to leave it unset. An existing "
|
|
88
|
+
"value in the template is kept.")
|
|
86
89
|
parser.add_argument("--template", dest="template_path", default=None,
|
|
87
90
|
help="Existing COGNAC UDF file (schema template). "
|
|
88
91
|
"Defaults to the built-in template; a .udf next to the "
|
|
@@ -233,6 +236,19 @@ def _from_top_parser():
|
|
|
233
236
|
"originals: the [ molecules ] order picks the "
|
|
234
237
|
"atoms of every frame. A name that is not in "
|
|
235
238
|
"[ molecules ] is an error.")
|
|
239
|
+
parser.add_argument("--for-viewing", dest="for_viewing",
|
|
240
|
+
action="store_true",
|
|
241
|
+
help="Write a file to be LOOKED AT, not run. Terms "
|
|
242
|
+
"the engine cannot hold (a dihedral whose phase "
|
|
243
|
+
"is neither 0 nor 180, for one) are left out "
|
|
244
|
+
"instead of failing the conversion, never "
|
|
245
|
+
"rewritten into a different one, and each "
|
|
246
|
+
"virtual site becomes a particle tied to its "
|
|
247
|
+
"first host. What the file does not reproduce is "
|
|
248
|
+
"warned about and written to <out>.notes.txt "
|
|
249
|
+
"beside it. The structure, the molecules and the "
|
|
250
|
+
"trajectory are complete; the force field is "
|
|
251
|
+
"not.")
|
|
236
252
|
parser.add_argument("--allow-unsupported", dest="allow_unsupported",
|
|
237
253
|
action="store_true",
|
|
238
254
|
help="Convert even when the .top contains terms "
|
|
@@ -402,7 +418,7 @@ def _run_from_top(argv: list) -> None:
|
|
|
402
418
|
print("Energy dumped: {}".format(energy_path))
|
|
403
419
|
|
|
404
420
|
from .top_exporter import TopExporter
|
|
405
|
-
TopExporter().export(top_path, gro_path, template_path, out_path,
|
|
421
|
+
decision = TopExporter().export(top_path, gro_path, template_path, out_path,
|
|
406
422
|
mdp_path=args.mdp_path,
|
|
407
423
|
cognac_version=args.cognac_version,
|
|
408
424
|
topology_only=args.topology_only,
|
|
@@ -412,12 +428,14 @@ def _run_from_top(argv: list) -> None:
|
|
|
412
428
|
max_frames=args.max_frames,
|
|
413
429
|
frame_step=args.frame_step,
|
|
414
430
|
allow_unsupported=args.allow_unsupported,
|
|
431
|
+
for_viewing=args.for_viewing,
|
|
415
432
|
constraints_as_bonds=constraints_k,
|
|
416
433
|
keep_molecules=keep_molecules,
|
|
417
434
|
make_whole=args.make_whole,
|
|
418
435
|
force_field=args.force_field,
|
|
419
436
|
nh_dof=args.nh_dof)
|
|
420
437
|
print("Written: {}".format(out_path))
|
|
438
|
+
print(_force_field_line(decision, args.force_field))
|
|
421
439
|
if args.topology_only:
|
|
422
440
|
if args.initial_gro_path:
|
|
423
441
|
print(f" (topology + 1 initial frame from {args.initial_gro_path!s}. "
|
|
@@ -454,6 +472,18 @@ def _usage(argv) -> None:
|
|
|
454
472
|
print(_from_top_parser().format_help())
|
|
455
473
|
|
|
456
474
|
|
|
475
|
+
def _force_field_line(decision, requested) -> str:
|
|
476
|
+
"""One line on what went into Unit_Parameter.Comment, for the log a GUI shows."""
|
|
477
|
+
from .udf_writer import ff_comment
|
|
478
|
+
if decision is None:
|
|
479
|
+
return "Force field: (not decided)"
|
|
480
|
+
if decision.name:
|
|
481
|
+
how = "decided from the topology" if str(requested).strip().lower() == "auto" else "as given"
|
|
482
|
+
return "Force field: {} ({}), {}".format(decision.name, ff_comment(decision.name), how)
|
|
483
|
+
return ("Force field: not written ({}). Name it with --ff <name>."
|
|
484
|
+
.format("; ".join(decision.reasons) or "left unset"))
|
|
485
|
+
|
|
486
|
+
|
|
457
487
|
def main(argv=None):
|
|
458
488
|
"""gro2udfのコマンドラインエントリポイント。
|
|
459
489
|
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Which force field a GROMACS topology came from, for ``--ff auto``.
|
|
3
|
+
|
|
4
|
+
``Unit_Parameter.Comment`` carries ``FF=n`` (see :mod:`.udf_writer`), and a
|
|
5
|
+
``.top`` does not say which force field it was built with. This module looks
|
|
6
|
+
at what the topology does say and names one -- or says why it cannot.
|
|
7
|
+
|
|
8
|
+
Evidence, strongest first:
|
|
9
|
+
|
|
10
|
+
1. ``#include`` names: ``amber14sb.ff/forcefield.itp``, ``oplsaa.ff/...``,
|
|
11
|
+
``charmm36.ff/...``, an ``.itp`` with ``gaff2`` / ``gaff`` in its name.
|
|
12
|
+
2. ``[ atomtypes ]``: lower-case GAFF-style names (``c3``, ``hc``) are told
|
|
13
|
+
apart as GAFF or GAFF2 by their Lennard-Jones values, which differ for
|
|
14
|
+
77 of the 80 types the two share (GAFF 1.81 / GAFF2 2.2.20); upper-case
|
|
15
|
+
AMBER protein types (``CT``, ``HC``, ``N3``); ``opls_123``.
|
|
16
|
+
3. ``[ defaults ]``: combination rule and fudge factors -- AMBER-family
|
|
17
|
+
(2, 0.5, 0.8333), OPLS (3, 0.5, 0.5), CHARMM (2, 1.0, 1.0). Used to
|
|
18
|
+
rule out, not to name.
|
|
19
|
+
|
|
20
|
+
Only the types the molecules use count, and not those of water and ions
|
|
21
|
+
(molecules of only O and H with at most four atoms, and single-atom
|
|
22
|
+
molecules): every force field brings them.
|
|
23
|
+
|
|
24
|
+
Nothing is guessed. Two families (a protein in AMBER types and a ligand in
|
|
25
|
+
GAFF2), a family without an ``FF=n`` number (CHARMM), types that match no
|
|
26
|
+
table, or ``[ defaults ]`` that contradict the types: no name, and the
|
|
27
|
+
reasons say which. ``amber20`` is never chosen here; the topology does not
|
|
28
|
+
tell it from ``amber``.
|
|
29
|
+
"""
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import os
|
|
33
|
+
import re
|
|
34
|
+
from dataclasses import dataclass, field
|
|
35
|
+
from typing import Dict, Iterable, List, Optional, Sequence, Set
|
|
36
|
+
|
|
37
|
+
#: Lennard-Jones (sigma nm, epsilon kJ/mol) of the types whose GAFF and GAFF2
|
|
38
|
+
#: values differ by more than 2 % -- gaff.dat 1.81 and gaff2.dat 2.2.20.
|
|
39
|
+
_GAFF_LJ = {"br": (0.359923, 1.75728), "c": (0.339967, 0.359824), "c1": (0.339967, 0.87864), "c2": (0.339967, 0.359824), "ca": (0.339967, 0.359824), "cc": (0.339967, 0.359824), "cd": (0.339967, 0.359824), "ce": (0.339967, 0.359824), "cf": (0.339967, 0.359824), "cg": (0.339967, 0.87864), "ch": (0.339967, 0.87864), "cp": (0.339967, 0.359824), "cq": (0.339967, 0.359824), "cu": (0.339967, 0.359824), "cv": (0.339967, 0.359824), "cx": (0.339967, 0.359824), "cy": (0.339967, 0.359824), "cz": (0.339967, 0.359824), "f": (0.311815, 0.255224), "h1": (0.247135, 0.065689), "h2": (0.229317, 0.065689), "h3": (0.211499, 0.065689), "h4": (0.251055, 0.06276), "h5": (0.242146, 0.06276), "ha": (0.259964, 0.06276), "hc": (0.264953, 0.065689), "hn": (0.106908, 0.065689), "hp": (0.106908, 0.065689), "hs": (0.106908, 0.065689), "hx": (0.195998, 0.065689), "n": (0.325, 0.71128), "n1": (0.325, 0.71128), "n2": (0.325, 0.71128), "n3": (0.325, 0.71128), "n4": (0.325, 0.71128), "na": (0.325, 0.71128), "nb": (0.325, 0.71128), "nc": (0.325, 0.71128), "nd": (0.325, 0.71128), "ne": (0.325, 0.71128), "nf": (0.325, 0.71128), "nh": (0.325, 0.71128), "ni": (0.325, 0.71128), "nj": (0.325, 0.71128), "nk": (0.325, 0.71128), "nl": (0.325, 0.71128), "nm": (0.325, 0.71128), "nn": (0.325, 0.71128), "no": (0.325, 0.71128), "np": (0.325, 0.71128), "nq": (0.325, 0.71128), "o": (0.295992, 0.87864), "oh": (0.306647, 0.880314), "op": (0.300001, 0.71128), "oq": (0.300001, 0.71128), "os": (0.300001, 0.71128), "p2": (0.374177, 0.8368), "p3": (0.374177, 0.8368), "p4": (0.374177, 0.8368), "p5": (0.374177, 0.8368), "pb": (0.374177, 0.8368), "pc": (0.374177, 0.8368), "pd": (0.374177, 0.8368), "pe": (0.374177, 0.8368), "pf": (0.374177, 0.8368), "px": (0.374177, 0.8368), "py": (0.374177, 0.8368), "s": (0.356359, 1.046), "s2": (0.356359, 1.046), "s4": (0.356359, 1.046), "s6": (0.356359, 1.046), "sh": (0.356359, 1.046), "sp": (0.356359, 1.046), "sq": (0.356359, 1.046), "ss": (0.356359, 1.046), "sx": (0.356359, 1.046), "sy": (0.356359, 1.046)}
|
|
40
|
+
_GAFF2_LJ = {"br": (0.361259, 1.645149), "c": (0.331521, 0.413379), "c1": (0.347896, 0.667766), "c2": (0.331521, 0.413379), "ca": (0.331521, 0.413379), "cc": (0.331521, 0.413379), "cd": (0.331521, 0.413379), "ce": (0.331521, 0.413379), "cf": (0.331521, 0.413379), "cg": (0.347896, 0.667766), "ch": (0.347896, 0.667766), "cp": (0.331521, 0.413379), "cq": (0.331521, 0.413379), "cu": (0.331521, 0.413379), "cv": (0.331521, 0.413379), "cx": (0.339771, 0.451035), "cy": (0.339771, 0.451035), "cz": (0.331521, 0.413379), "f": (0.303422, 0.348109), "h1": (0.2422, 0.087027), "h2": (0.224382, 0.087027), "h3": (0.206564, 0.087027), "h4": (0.253639, 0.067362), "h5": (0.24473, 0.067362), "ha": (0.262548, 0.067362), "hc": (0.260018, 0.087027), "hn": (0.11065, 0.04184), "hp": (0.10746, 0.06025), "hs": (0.108903, 0.051882), "hx": (0.188746, 0.087027), "n": (0.318086, 0.684502), "n1": (0.327352, 0.459403), "n2": (0.338417, 0.393714), "n3": (0.33651, 0.358987), "n4": (0.249951, 16.212163), "na": (0.320581, 0.854373), "nb": (0.338417, 0.393714), "nc": (0.338417, 0.393714), "nd": (0.338417, 0.393714), "ne": (0.338417, 0.393714), "nf": (0.338417, 0.393714), "nh": (0.318995, 0.89956), "ni": (0.318086, 0.684502), "nj": (0.318086, 0.684502), "nk": (0.25886, 10.649535), "nl": (0.25886, 10.649535), "nm": (0.318995, 0.89956), "nn": (0.318995, 0.89956), "no": (0.33651, 0.358987), "np": (0.33651, 0.358987), "nq": (0.33651, 0.358987), "o": (0.304812, 0.612119), "oh": (0.324287, 0.389112), "op": (0.31561, 0.303758), "oq": (0.31561, 0.303758), "os": (0.31561, 0.303758), "p2": (0.369402, 0.960228), "p3": (0.369402, 0.960228), "p4": (0.369402, 0.960228), "p5": (0.369402, 0.960228), "pb": (0.369402, 0.960228), "pc": (0.369402, 0.960228), "pd": (0.369402, 0.960228), "pe": (0.369402, 0.960228), "pf": (0.369402, 0.960228), "px": (0.369402, 0.960228), "py": (0.369402, 0.960228), "s": (0.353241, 1.181562), "s2": (0.353241, 1.181562), "s4": (0.353241, 1.181562), "s6": (0.40584, 0.256898), "sh": (0.353241, 1.181562), "sp": (0.353241, 1.181562), "sq": (0.353241, 1.181562), "ss": (0.353241, 1.181562), "sx": (0.353241, 1.181562), "sy": (0.40584, 0.256898)}
|
|
41
|
+
|
|
42
|
+
#: Every GAFF / GAFF2 type name. Those not in the tables above (c3, cl, ho,
|
|
43
|
+
#: i -- close or zero in both -- and the ones only one of them has) are
|
|
44
|
+
#: GAFF-family but do not tell GAFF from GAFF2.
|
|
45
|
+
_GAFF_NAMES = frozenset("""
|
|
46
|
+
br c c1 c2 c3 c5 c6 ca cc cd ce cf cg ch cl cp cq cs cu cv cx cy cz f h1 h2 h3 h4
|
|
47
|
+
h5 ha hc hn ho hp hs hw hx i n n+ n1 n2 n3 n4 n5 n6 n7 n8 n9 na nb nc nd ne nf nh
|
|
48
|
+
ni nj nk nl nm nn no np nq ns nt nu nv nx ny nz o oh op oq os ow p2 p3 p4 p5 pb pc
|
|
49
|
+
pd pe pf px py s s2 s4 s6 sh sp sq ss sx sy
|
|
50
|
+
""".split())
|
|
51
|
+
|
|
52
|
+
#: Relative tolerance on sigma and epsilon (topologies print 5-6 digits).
|
|
53
|
+
_LJ_RTOL = 0.005
|
|
54
|
+
|
|
55
|
+
#: Upper-case atom types of the AMBER protein / nucleic force fields
|
|
56
|
+
#: (parm99 / ff14SB families). A topology made from them prints these names.
|
|
57
|
+
_AMBER_TYPES = frozenset("""
|
|
58
|
+
C CA CB CC CD CK CM CN CQ CR CT CV CW C* CX CS 2C 3C C4 C5 C8 CO CI
|
|
59
|
+
H H1 H2 H3 H4 H5 HA HC HO HP HS HZ HW
|
|
60
|
+
N N2 N3 N* NA NB NC NT NY
|
|
61
|
+
O O2 OH OS OW P S SH
|
|
62
|
+
""".split())
|
|
63
|
+
|
|
64
|
+
#: The Lennard-Jones (sigma nm, epsilon kJ/mol) pairs of parm10.dat (parm99 +
|
|
65
|
+
#: ff99SB + bsc0 + OL3; ff14SB keeps them). An upper-case type counts as
|
|
66
|
+
#: AMBER only with one of these: ParmEd renames types (C1, O1, H1 ...) and a
|
|
67
|
+
#: name alone would claim them.
|
|
68
|
+
_AMBER_LJ = [(0.0, 0.0), (0.106908, 0.065689), (0.141225, 3.743425), (0.195998, 0.065689), (0.211499, 0.065689), (0.229317, 0.065689), (0.242146, 0.06276), (0.247135, 0.065689), (0.251055, 0.06276), (0.259964, 0.06276), (0.264953, 0.065689), (0.295992, 0.87864), (0.300001, 0.71128), (0.30524, 1.923757), (0.306647, 0.880314), (0.311815, 0.255224), (0.325, 0.71128), (0.329633, 0.71128), (0.339967, 0.359824), (0.339967, 0.45773), (0.347094, 1.10876), (0.356359, 1.046), (0.374177, 0.8368), (0.395559, 1.33888), (0.418722, 1.6736)]
|
|
69
|
+
|
|
70
|
+
#: [ defaults ] (comb-rule, fudgeLJ, fudgeQQ) of each family.
|
|
71
|
+
_DEFAULTS = {"amber": (2, 0.5, 0.8333), "opls": (3, 0.5, 0.5), "charmm": (2, 1.0, 1.0)}
|
|
72
|
+
|
|
73
|
+
#: Family -> the gro2udf force-field name it is written as (None: no FF=n number).
|
|
74
|
+
_NAME = {"amber": "amber", "gaff": "gaff", "gaff2": "gaff2", "opls": "oplsaa", "charmm": None,
|
|
75
|
+
"gaff or gaff2": None}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass
|
|
79
|
+
class FFDecision:
|
|
80
|
+
"""What ``--ff auto`` decided. ``name`` is a gro2udf force-field name
|
|
81
|
+
(``gaff2``, ``amber`` ...) or ``None`` when no single one fits."""
|
|
82
|
+
name: Optional[str]
|
|
83
|
+
families: Dict[str, List[str]] = field(default_factory=dict) # family -> evidence
|
|
84
|
+
reasons: List[str] = field(default_factory=list)
|
|
85
|
+
|
|
86
|
+
def summary(self) -> str:
|
|
87
|
+
ev = "; ".join("%s: %s" % (f, ", ".join(e[:4]) + (" ..." if len(e) > 4 else ""))
|
|
88
|
+
for f, e in sorted(self.families.items()))
|
|
89
|
+
return ev or "no evidence"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def include_names(top_path: str, _seen: Optional[Set[str]] = None) -> List[str]:
|
|
93
|
+
"""The ``#include`` names of *top_path* and of the files it includes that
|
|
94
|
+
can be read (relative to the including file). A force-field directory
|
|
95
|
+
(``amber14sb.ff/forcefield.itp``) usually lives in GROMACS' own library
|
|
96
|
+
and is not read -- its name is the evidence."""
|
|
97
|
+
seen = _seen if _seen is not None else set()
|
|
98
|
+
path = os.path.abspath(top_path)
|
|
99
|
+
if path in seen:
|
|
100
|
+
return []
|
|
101
|
+
seen.add(path)
|
|
102
|
+
out: List[str] = []
|
|
103
|
+
try:
|
|
104
|
+
with open(path, encoding="utf-8", errors="replace") as f:
|
|
105
|
+
lines = f.readlines()
|
|
106
|
+
except OSError:
|
|
107
|
+
return out
|
|
108
|
+
for line in lines:
|
|
109
|
+
s = line.strip()
|
|
110
|
+
if not s.startswith("#include"):
|
|
111
|
+
continue
|
|
112
|
+
parts = s.split(None, 1)
|
|
113
|
+
if len(parts) < 2:
|
|
114
|
+
continue
|
|
115
|
+
name = parts[1].strip().strip('"<>\'')
|
|
116
|
+
out.append(name)
|
|
117
|
+
sub = os.path.join(os.path.dirname(path), name)
|
|
118
|
+
if os.path.isfile(sub):
|
|
119
|
+
out.extend(include_names(sub, seen))
|
|
120
|
+
return out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _family_of_include(name: str) -> Optional[str]:
|
|
124
|
+
n = os.path.basename(os.path.dirname(name)) + "/" + os.path.basename(name)
|
|
125
|
+
n = n.lower()
|
|
126
|
+
if re.search(r"\bamber[\w\-]*\.ff/", n):
|
|
127
|
+
return "amber"
|
|
128
|
+
if "oplsaa.ff/" in n:
|
|
129
|
+
return "opls"
|
|
130
|
+
if re.search(r"charmm[\w\-]*\.ff/", n):
|
|
131
|
+
return "charmm"
|
|
132
|
+
base = os.path.basename(name).lower()
|
|
133
|
+
if "gaff2" in base:
|
|
134
|
+
return "gaff2"
|
|
135
|
+
if "gaff" in base:
|
|
136
|
+
return "gaff"
|
|
137
|
+
return None
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _close(a, b) -> bool:
|
|
141
|
+
return all(abs(x - y) <= _LJ_RTOL * max(abs(x), abs(y), 1e-12) for x, y in zip(a, b))
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _solvent_types(model) -> Set[str]:
|
|
145
|
+
"""Types used only by water and single-atom molecules."""
|
|
146
|
+
solvent, other = set(), set()
|
|
147
|
+
for mol in model.mol_specs:
|
|
148
|
+
els = {a.element for a in mol.atoms}
|
|
149
|
+
is_solvent = len(mol.atoms) == 1 or (len(mol.atoms) <= 4 and els <= {"O", "H", ""})
|
|
150
|
+
(solvent if is_solvent else other).update(a.type_name for a in mol.atoms)
|
|
151
|
+
return solvent - other
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def detect(model, includes: Sequence[str] = ()) -> FFDecision:
|
|
155
|
+
"""Name the force field of *model* (a :class:`TopModel`), or say why not."""
|
|
156
|
+
fam: Dict[str, List[str]] = {}
|
|
157
|
+
|
|
158
|
+
def add(f, ev):
|
|
159
|
+
fam.setdefault(f, [])
|
|
160
|
+
if ev not in fam[f]:
|
|
161
|
+
fam[f].append(ev)
|
|
162
|
+
|
|
163
|
+
for inc in includes:
|
|
164
|
+
f = _family_of_include(inc)
|
|
165
|
+
if f:
|
|
166
|
+
add(f, "#include " + inc)
|
|
167
|
+
|
|
168
|
+
# Only the types the molecules use: a force-field directory's
|
|
169
|
+
# ffnonbonded.itp lists every type it has, used or not.
|
|
170
|
+
skip = _solvent_types(model)
|
|
171
|
+
used = {a.type_name for mol in model.mol_specs for a in mol.atoms}
|
|
172
|
+
unmatched: List[str] = []
|
|
173
|
+
neutral: List[str] = []
|
|
174
|
+
for t in model.atom_type_specs:
|
|
175
|
+
name = t.name
|
|
176
|
+
if name in skip or name not in used:
|
|
177
|
+
continue
|
|
178
|
+
if re.match(r"^opls_\d+$", name):
|
|
179
|
+
add("opls", name)
|
|
180
|
+
elif name in _AMBER_TYPES and any(
|
|
181
|
+
_close((t.sigma, t.epsilon), lj) if lj[1] else t.epsilon == 0.0
|
|
182
|
+
for lj in _AMBER_LJ):
|
|
183
|
+
add("amber", name)
|
|
184
|
+
elif name in _GAFF_LJ:
|
|
185
|
+
lj = (t.sigma, t.epsilon)
|
|
186
|
+
if _close(lj, _GAFF2_LJ[name]):
|
|
187
|
+
add("gaff2", name)
|
|
188
|
+
elif _close(lj, _GAFF_LJ[name]):
|
|
189
|
+
add("gaff", name)
|
|
190
|
+
else:
|
|
191
|
+
unmatched.append(name)
|
|
192
|
+
elif name in _GAFF_NAMES:
|
|
193
|
+
neutral.append(name)
|
|
194
|
+
else:
|
|
195
|
+
unmatched.append(name)
|
|
196
|
+
if neutral and not ({"gaff", "gaff2"} & set(fam)):
|
|
197
|
+
fam["gaff or gaff2"] = neutral
|
|
198
|
+
|
|
199
|
+
reasons: List[str] = []
|
|
200
|
+
if unmatched:
|
|
201
|
+
reasons.append("atom types no table names: %s%s"
|
|
202
|
+
% (", ".join(unmatched[:8]), " ..." if len(unmatched) > 8 else ""))
|
|
203
|
+
d = (model.comb_rule, round(model.fudge_lj, 4), round(model.fudge_qq, 4))
|
|
204
|
+
by_defaults = [f for f, v in _DEFAULTS.items()
|
|
205
|
+
if v[0] == d[0] and abs(v[1] - d[1]) < 1e-3 and abs(v[2] - d[2]) < 2e-3]
|
|
206
|
+
|
|
207
|
+
families = sorted(fam)
|
|
208
|
+
if not families:
|
|
209
|
+
reasons.append("nothing in the topology names a force field")
|
|
210
|
+
return FFDecision(None, fam, reasons)
|
|
211
|
+
if len(families) > 1:
|
|
212
|
+
reasons.insert(0, "more than one force field: %s" % ", ".join(families))
|
|
213
|
+
return FFDecision(None, fam, reasons)
|
|
214
|
+
f = families[0]
|
|
215
|
+
group = "amber" if f in ("amber", "gaff", "gaff2", "gaff or gaff2") else f
|
|
216
|
+
if by_defaults and group not in by_defaults:
|
|
217
|
+
reasons.insert(0, "[ defaults ] %s fit %s, not %s" % (d, by_defaults[0], f))
|
|
218
|
+
return FFDecision(None, fam, reasons)
|
|
219
|
+
if unmatched:
|
|
220
|
+
reasons.insert(0, "%s types, but also types it cannot place" % f)
|
|
221
|
+
return FFDecision(None, fam, reasons)
|
|
222
|
+
if f == "gaff or gaff2":
|
|
223
|
+
reasons.insert(0, "GAFF-family types, but none that tells GAFF from GAFF2 (%s)"
|
|
224
|
+
% ", ".join(fam[f][:6]))
|
|
225
|
+
return FFDecision(None, fam, reasons)
|
|
226
|
+
if _NAME[f] is None:
|
|
227
|
+
reasons.insert(0, "%s has no FF=n number" % f)
|
|
228
|
+
return FFDecision(None, fam, reasons)
|
|
229
|
+
return FFDecision(_NAME[f], fam, reasons)
|