openff-toolkit 0.18.0__py3-none-any.whl
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.
- devtools/scripts/build_cookiecutter_json.py +22 -0
- docs/conf.py +296 -0
- docs/conftest.py +23 -0
- examples/conformer_energies/conformer_energies.py +143 -0
- examples/deprecated/SMIRNOFF_comparison/compare_molecule_energies.py +48 -0
- examples/deprecated/SMIRNOFF_comparison/compare_set_energies.py +58 -0
- examples/deprecated/liquid_box/create_mol2_pdb/create_mol2_pdb.py +193 -0
- examples/deprecated/liquid_box/openff_simulation.py +72 -0
- examples/deprecated/mixedFF_structure/generate_mixedFF_complex.py +56 -0
- examples/deprecated/testing/test_impropers/tleap_tools.py +120 -0
- examples/examples_helper.py +61 -0
- openff/toolkit/__init__.py +101 -0
- openff/toolkit/_tests/__init__.py +0 -0
- openff/toolkit/_tests/_stale_tests.py +146 -0
- openff/toolkit/_tests/conftest.py +108 -0
- openff/toolkit/_tests/create_molecules.py +494 -0
- openff/toolkit/_tests/mocking.py +145 -0
- openff/toolkit/_tests/molecule/__init__.py +1 -0
- openff/toolkit/_tests/molecule/test_state_enumeration.py +302 -0
- openff/toolkit/_tests/test_energies.py +136 -0
- openff/toolkit/_tests/test_examples.py +109 -0
- openff/toolkit/_tests/test_forcefield.py +3864 -0
- openff/toolkit/_tests/test_interchange.py +19 -0
- openff/toolkit/_tests/test_io.py +19 -0
- openff/toolkit/_tests/test_links.py +73 -0
- openff/toolkit/_tests/test_mm_molecule.py +404 -0
- openff/toolkit/_tests/test_molecule.py +4246 -0
- openff/toolkit/_tests/test_nagl.py +169 -0
- openff/toolkit/_tests/test_parameter_plugins.py +89 -0
- openff/toolkit/_tests/test_parameters.py +2898 -0
- openff/toolkit/_tests/test_toolkit_io.py +1088 -0
- openff/toolkit/_tests/test_toolkits.py +4418 -0
- openff/toolkit/_tests/test_topology.py +2485 -0
- openff/toolkit/_tests/test_utils.py +101 -0
- openff/toolkit/_tests/test_utils_callback.py +178 -0
- openff/toolkit/_tests/test_utils_collections.py +263 -0
- openff/toolkit/_tests/test_utils_serialization.py +168 -0
- openff/toolkit/_tests/utils.py +1747 -0
- openff/toolkit/data/README.md +8 -0
- openff/toolkit/data/molecules/AlkEthOH_test_filt1_ff.mol2 +2026 -0
- openff/toolkit/data/molecules/AlkEthOH_test_filt1_tripos.mol2 +2026 -0
- openff/toolkit/data/molecules/AlkEthOH_tripos.tar.gz +0 -0
- openff/toolkit/data/molecules/CID20742535_anion.sdf +50 -0
- openff/toolkit/data/molecules/CID20742535_neutral.sdf +51 -0
- openff/toolkit/data/molecules/FreeSolv.tar.gz +0 -0
- openff/toolkit/data/molecules/MiniDrugBank.sdf +33988 -0
- openff/toolkit/data/molecules/MiniDrugBank_tripos.mol2 +35462 -0
- openff/toolkit/data/molecules/PT2385.sdf +90 -0
- openff/toolkit/data/molecules/QL8.sdf +401 -0
- openff/toolkit/data/molecules/README.md +21 -0
- openff/toolkit/data/molecules/benzene.crd +8 -0
- openff/toolkit/data/molecules/benzene.mol2 +34 -0
- openff/toolkit/data/molecules/benzene.top +166 -0
- openff/toolkit/data/molecules/butane_multi.sdf +231 -0
- openff/toolkit/data/molecules/cyclohexane.mol2 +44 -0
- openff/toolkit/data/molecules/ethanol.mol2 +25 -0
- openff/toolkit/data/molecules/ethanol.sdf +23 -0
- openff/toolkit/data/molecules/ethanol_partial_charges.sdf +26 -0
- openff/toolkit/data/molecules/ethanol_reordered.mol2 +25 -0
- openff/toolkit/data/molecules/ethanol_reordered.sdf +23 -0
- openff/toolkit/data/molecules/ethene_rdkit.sdf +17 -0
- openff/toolkit/data/molecules/laromustine_ff.mol2 +71 -0
- openff/toolkit/data/molecules/laromustine_tripos.mol2 +71 -0
- openff/toolkit/data/molecules/methane_multiconformer.sdf +32 -0
- openff/toolkit/data/molecules/methane_multiconformer_properties.sdf +45 -0
- openff/toolkit/data/molecules/nh4.pdb +7 -0
- openff/toolkit/data/molecules/po4_phenylphosphate.pdb +46 -0
- openff/toolkit/data/molecules/ruxolitinib_conformers.sdf +910 -0
- openff/toolkit/data/molecules/toluene.mol2 +38 -0
- openff/toolkit/data/molecules/toluene.mol2.gz +0 -0
- openff/toolkit/data/molecules/toluene.pdb +30 -0
- openff/toolkit/data/molecules/toluene.sdf +36 -0
- openff/toolkit/data/molecules/toluene_charged.mol2 +38 -0
- openff/toolkit/data/molecules/z_3_hydroxy_propenal.sdf +23 -0
- openff/toolkit/data/proteins/5tbm_complex_solv.pdb +1928 -0
- openff/toolkit/data/proteins/5tbm_complex_solv_box.pdb +19563 -0
- openff/toolkit/data/proteins/CTerminal_ALA.pdb +20 -0
- openff/toolkit/data/proteins/CTerminal_ALA.sdf +43 -0
- openff/toolkit/data/proteins/CTerminal_ALA_ALA.pdb +30 -0
- openff/toolkit/data/proteins/CTerminal_ALA_ALA_misnamedH.pdb +30 -0
- openff/toolkit/data/proteins/CTerminal_ARG.pdb +34 -0
- openff/toolkit/data/proteins/CTerminal_TRP.pdb +34 -0
- openff/toolkit/data/proteins/MainChain_ALA.pdb +25 -0
- openff/toolkit/data/proteins/MainChain_ALA.sdf +52 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA.pdb +35 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA.sdf +69 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA_icodes.pdb +35 -0
- openff/toolkit/data/proteins/MainChain_ALA_ALA_no_hydrogens.pdb +17 -0
- openff/toolkit/data/proteins/MainChain_ARG.pdb +39 -0
- openff/toolkit/data/proteins/MainChain_ARG.sdf +81 -0
- openff/toolkit/data/proteins/MainChain_CYM.pdb +25 -0
- openff/toolkit/data/proteins/MainChain_CYS.pdb +26 -0
- openff/toolkit/data/proteins/MainChain_CYX.pdb +48 -0
- openff/toolkit/data/proteins/MainChain_CYX.sdf +96 -0
- openff/toolkit/data/proteins/MainChain_GLH.sdf +64 -0
- openff/toolkit/data/proteins/MainChain_GLU.sdf +63 -0
- openff/toolkit/data/proteins/MainChain_HID.pdb +32 -0
- openff/toolkit/data/proteins/MainChain_HIE.pdb +32 -0
- openff/toolkit/data/proteins/MainChain_HIE.sdf +67 -0
- openff/toolkit/data/proteins/MainChain_HIP.pdb +33 -0
- openff/toolkit/data/proteins/MainChain_HIP.sdf +70 -0
- openff/toolkit/data/proteins/MainChain_PRO.pdb +29 -0
- openff/toolkit/data/proteins/MainChain_TRP.pdb +39 -0
- openff/toolkit/data/proteins/NTerminal_ALA.pdb +21 -0
- openff/toolkit/data/proteins/NTerminal_ALA.sdf +45 -0
- openff/toolkit/data/proteins/NTerminal_ALA_ALA.pdb +31 -0
- openff/toolkit/data/proteins/NTerminal_ARG.pdb +35 -0
- openff/toolkit/data/proteins/NTerminal_TRP.pdb +35 -0
- openff/toolkit/data/proteins/T4-protein-unprocessed-4w51.pdb +1892 -0
- openff/toolkit/data/proteins/T4-protein.mol2 +5461 -0
- openff/toolkit/data/proteins/T4-protein.pdb +2637 -0
- openff/toolkit/data/proteins/T4-protein.sdf +5318 -0
- openff/toolkit/data/proteins/T4_protein_waters.pdb +2965 -0
- openff/toolkit/data/proteins/TwoMol_SER_CYS.pdb +50 -0
- openff/toolkit/data/proteins/aa_residues_substructures_explicit_bond_orders_with_caps.json +6435 -0
- openff/toolkit/data/proteins/aa_residues_substructures_explicit_bond_orders_with_caps_explicit_connectivity.json +6675 -0
- openff/toolkit/data/proteins/aa_residues_substructures_with_caps.json +6297 -0
- openff/toolkit/data/proteins/ace-ZZZ-gly-nme.pdb +78 -0
- openff/toolkit/data/proteins/ace-ZZZ-gly-nme.sdf +98 -0
- openff/toolkit/data/proteins/ace-a10-nme.sdf +229 -0
- openff/toolkit/data/proteins/ace-ala-nh2.pdb +21 -0
- openff/toolkit/data/proteins/fluoresceine_dyed_helix_capped.pdb +338 -0
- openff/toolkit/data/proteins/neutral_arginine.pdb +31 -0
- openff/toolkit/data/proteins/split_chain.pdb +74 -0
- openff/toolkit/data/proteins/split_chain_reordered.pdb +74 -0
- openff/toolkit/data/reference_energies/README.md +6 -0
- openff/toolkit/data/reference_energies/reference_0.8.0.json +1 -0
- openff/toolkit/data/reference_energies/reference_0.8.0.json.txt +180 -0
- openff/toolkit/data/reference_energies/reference_after_1007.json +1 -0
- openff/toolkit/data/reference_energies/reference_after_1007.json.txt +350 -0
- openff/toolkit/data/reference_energies/reference_after_802.json +1 -0
- openff/toolkit/data/reference_energies/reference_after_802.json.txt +291 -0
- openff/toolkit/data/systems/README.md +3 -0
- openff/toolkit/data/systems/amber/cyclohexane_ethanol_0.4_0.6.inpcrd +1511 -0
- openff/toolkit/data/systems/amber/cyclohexane_ethanol_0.4_0.6.prmtop +13367 -0
- openff/toolkit/data/systems/monomers/butanol.mol2 +38 -0
- openff/toolkit/data/systems/monomers/butanol.sdf +88 -0
- openff/toolkit/data/systems/monomers/cyclohexane.mol2 +45 -0
- openff/toolkit/data/systems/monomers/cyclohexane.sdf +105 -0
- openff/toolkit/data/systems/monomers/ethanol.mol2 +26 -0
- openff/toolkit/data/systems/monomers/ethanol.sdf +58 -0
- openff/toolkit/data/systems/monomers/methane.mol2 +18 -0
- openff/toolkit/data/systems/monomers/methane.sdf +38 -0
- openff/toolkit/data/systems/monomers/propane.mol2 +30 -0
- openff/toolkit/data/systems/monomers/propane.sdf +68 -0
- openff/toolkit/data/systems/monomers/tip3p_water.mol2 +14 -0
- openff/toolkit/data/systems/monomers/water.mol2 +14 -0
- openff/toolkit/data/systems/monomers/water.sdf +28 -0
- openff/toolkit/data/systems/packmol_boxes/cyclohexane_ethanol_0.4_0.6.pdb +6272 -0
- openff/toolkit/data/systems/packmol_boxes/cyclohexane_water.pdb +5524 -0
- openff/toolkit/data/systems/packmol_boxes/ethanol_water.pdb +5174 -0
- openff/toolkit/data/systems/packmol_boxes/propane_methane_butanol_0.2_0.3_0.5.pdb +7959 -0
- openff/toolkit/data/systems/test_systems/1_cyclohexane_1_ethanol.pdb +61 -0
- openff/toolkit/data/systems/test_systems/1_ethanol.pdb +24 -0
- openff/toolkit/data/systems/test_systems/1_ethanol_no_conect.pdb +15 -0
- openff/toolkit/data/systems/test_systems/1_ethanol_reordered.pdb +24 -0
- openff/toolkit/data/systems/test_systems/PE.pdb +67 -0
- openff/toolkit/data/systems/test_systems/README.md +3 -0
- openff/toolkit/data/systems/test_systems/T4_lysozyme_water_ions.pdb +29240 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH.offxml +61 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_GBSA.offxml +78 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_MDL.offxml +62 -0
- openff/toolkit/data/test_forcefields/Frosst_AlkEthOH_parmAtFrosst.offxml +64 -0
- openff/toolkit/data/test_forcefields/GBSA_HCT-1.0.offxml +21 -0
- openff/toolkit/data/test_forcefields/GBSA_OBC1-1.0.offxml +18 -0
- openff/toolkit/data/test_forcefields/GBSA_OBC2-1.0.offxml +18 -0
- openff/toolkit/data/test_forcefields/README.md +23 -0
- openff/toolkit/data/test_forcefields/ammonia_minimal.offxml +27 -0
- openff/toolkit/data/test_forcefields/benzene_minimal.offxml +29 -0
- openff/toolkit/data/test_forcefields/chargeincrement-test.offxml +16 -0
- openff/toolkit/data/test_forcefields/frcmod.Frosst_AlkEthOH_withIDs +85 -0
- openff/toolkit/data/test_forcefields/ion_charges.offxml +18 -0
- openff/toolkit/data/test_forcefields/mangled.offxml +9 -0
- openff/toolkit/data/test_forcefields/old/README.md +9 -0
- openff/toolkit/data/test_forcefields/old/hbonds.offxml +11 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_1.offxml +332 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_2.offxml +338 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_2_spec_0_3.offxml +329 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_1.offxml +342 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_2.offxml +348 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_fixed_spec_0_3.offxml +337 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_1.offxml +340 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_2.offxml +346 -0
- openff/toolkit/data/test_forcefields/old/test_ff_0_0_4_spec_0_3.offxml +337 -0
- openff/toolkit/data/test_forcefields/smirff99Frosst_reference_0_1_spec.offxml +349 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_experimental.offxml +343 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_reference_0_1_spec.offxml +349 -0
- openff/toolkit/data/test_forcefields/smirnoff99Frosst_reference_0_2_spec.offxml +356 -0
- openff/toolkit/data/test_forcefields/test_forcefield.offxml +346 -0
- openff/toolkit/data/test_forcefields/tip3p.offxml +22 -0
- openff/toolkit/data/test_forcefields/unsupported_smirnoff_version.offxml +9 -0
- openff/toolkit/topology/__init__.py +43 -0
- openff/toolkit/topology/_mm_molecule.py +663 -0
- openff/toolkit/topology/molecule.py +6102 -0
- openff/toolkit/topology/topology.py +2555 -0
- openff/toolkit/typing/__init__.py +1 -0
- openff/toolkit/typing/engines/__init__.py +1 -0
- openff/toolkit/typing/engines/smirnoff/__init__.py +31 -0
- openff/toolkit/typing/engines/smirnoff/forcefield.py +1440 -0
- openff/toolkit/typing/engines/smirnoff/io.py +234 -0
- openff/toolkit/typing/engines/smirnoff/parameters.py +3839 -0
- openff/toolkit/typing/engines/smirnoff/plugins.py +91 -0
- openff/toolkit/utils/__init__.py +57 -0
- openff/toolkit/utils/_viz.py +104 -0
- openff/toolkit/utils/ambertools_wrapper.py +507 -0
- openff/toolkit/utils/base_wrapper.py +268 -0
- openff/toolkit/utils/builtin_wrapper.py +136 -0
- openff/toolkit/utils/callback.py +187 -0
- openff/toolkit/utils/collections.py +247 -0
- openff/toolkit/utils/constants.py +18 -0
- openff/toolkit/utils/exceptions.py +766 -0
- openff/toolkit/utils/nagl_wrapper.py +164 -0
- openff/toolkit/utils/openeye_wrapper.py +2750 -0
- openff/toolkit/utils/rdkit_wrapper.py +3302 -0
- openff/toolkit/utils/serialization.py +466 -0
- openff/toolkit/utils/toolkit_registry.py +509 -0
- openff/toolkit/utils/toolkits.py +217 -0
- openff/toolkit/utils/utils.py +805 -0
- openff_toolkit-0.18.0.dist-info/METADATA +109 -0
- openff_toolkit-0.18.0.dist-info/RECORD +231 -0
- openff_toolkit-0.18.0.dist-info/WHEEL +5 -0
- openff_toolkit-0.18.0.dist-info/licenses/LICENSE +21 -0
- openff_toolkit-0.18.0.dist-info/top_level.txt +5 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.1.py +251 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.2.py +249 -0
- utilities/deprecated/convert_frosst/convert_frcmod_0.3.py +249 -0
- utilities/make_substructure_dict/_cif_to_substructure_dict.py +955 -0
- utilities/make_substructure_dict/_make_chemical_substructures.py +46 -0
- utilities/make_substructure_dict/_make_metadata_assignment_substructures.py +35 -0
- utilities/test_plugins/custom_plugins/handler_plugins.py +48 -0
- utilities/test_plugins/setup.py +19 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/bin/env python
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from openff.toolkit.typing.engines.smirnoff.forcefield import ForceField
|
|
5
|
+
|
|
6
|
+
# Function definitions for parsing sections within parameter file
|
|
7
|
+
def _parse_nonbon_line( line ):
|
|
8
|
+
"""Parse an AMBER frcmod nonbon line and return relevant parameters in a dictionary. AMBER uses rmin_half and epsilon in angstroms and kilocalories per mole."""
|
|
9
|
+
tmp = line.split()
|
|
10
|
+
params = {}
|
|
11
|
+
params['smirks'] = tmp[0]
|
|
12
|
+
params['rmin_half'] = tmp[1] + ' * angstrom'
|
|
13
|
+
params['epsilon'] = tmp[2] + ' * kilocalories_per_mole'
|
|
14
|
+
|
|
15
|
+
return params
|
|
16
|
+
|
|
17
|
+
def _parse_bond_line( line ):
|
|
18
|
+
"""Parse an AMBER frcmod BOND line and return relevant parameters in a dictionary. AMBER uses length and force constant, with the factor of two dropped. Here we multiply by the factor of two before returning. Units are angstroms and kilocalories per mole per square angstrom."""
|
|
19
|
+
|
|
20
|
+
tmp = line.split()
|
|
21
|
+
params = {}
|
|
22
|
+
params['smirks'] = tmp[0]
|
|
23
|
+
params['k'] = str(2*float(tmp[1])) + "* kilocalories_per_mole/angstrom**2"
|
|
24
|
+
params['length'] = tmp[2] + " * angstrom"
|
|
25
|
+
return params
|
|
26
|
+
|
|
27
|
+
def _parse_angl_line( line ):
|
|
28
|
+
"""Parse an AMBER frcmod ANGL line and return relevant parameters in a dictionary. AMBER uses angle and force constant, with the factor of two dropped. Here we multiply by the factor of two before returning. Units are degrees and kilocalories per mole."""
|
|
29
|
+
|
|
30
|
+
tmp = line.split()
|
|
31
|
+
params = {}
|
|
32
|
+
params['smirks'] = tmp[0]
|
|
33
|
+
params['k'] = str(2*float(tmp[1])) + " * kilocalories_per_mole/radian**2"
|
|
34
|
+
params['angle'] = tmp[2] + " * degree"
|
|
35
|
+
return params
|
|
36
|
+
|
|
37
|
+
def _parse_dihe_line( line ):
|
|
38
|
+
"""Parse an AMBER frcmod DIHE line and return relevant parameters in a dictionary. Units for k are kilocalories per mole."""
|
|
39
|
+
|
|
40
|
+
tmp = line.split()
|
|
41
|
+
params = {}
|
|
42
|
+
params['smirks'] = tmp[0]
|
|
43
|
+
params['idivf1'] = tmp[1]
|
|
44
|
+
params['k1'] = tmp[2] + " * kilocalories_per_mole"
|
|
45
|
+
params['phase1'] = tmp[3] + " * degree"
|
|
46
|
+
params['periodicity1'] = str(int(np.abs(float(tmp[4]))))
|
|
47
|
+
return params
|
|
48
|
+
|
|
49
|
+
def _parse_impr_line( line ):
|
|
50
|
+
"""Parse an AMBER frcmod DIHE line and return relevant parameters in a dictionary. Units for k are kilocalories per mole."""
|
|
51
|
+
|
|
52
|
+
tmp = line.split()
|
|
53
|
+
params = {}
|
|
54
|
+
params['smirks'] = tmp[0]
|
|
55
|
+
params['k1'] = tmp[1] + " * kilocalories_per_mole"
|
|
56
|
+
params['phase1'] = tmp[2] + " * degree"
|
|
57
|
+
params['periodicity1'] = str(int(np.abs(float(tmp[3]))))
|
|
58
|
+
return params
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def parse_frcmod(frcmod_file_name):
|
|
62
|
+
"""
|
|
63
|
+
Parse a smirnoffish FRCMOD file, returning a dict of lists containing the individual parameters that would go
|
|
64
|
+
into a "SMIRNOFF data" dictionary. When combined with section headers, this dictionary is suitable to be fed
|
|
65
|
+
into the ForceField initializer
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
frcmod_file_name : str
|
|
70
|
+
path to a smirnoffish FRCMOD file
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
parameter_lists : dict of list
|
|
75
|
+
Hierarchical dict of lists, containing parameter entries compliant with the SMIRNOFF spec version 0.2
|
|
76
|
+
author : str or None
|
|
77
|
+
Contents of the Author field, if any
|
|
78
|
+
date: str or None
|
|
79
|
+
Contents of the Date field, if any
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
# Obtain sections from target file
|
|
84
|
+
file = open(frcmod_file_name, 'r')
|
|
85
|
+
text = file.readlines()
|
|
86
|
+
file.close()
|
|
87
|
+
sections = {}
|
|
88
|
+
# Section names from frcmod which we will parse
|
|
89
|
+
sec_names = ['NONBON', 'BOND', 'ANGL', 'IMPR', 'DIHE']
|
|
90
|
+
sec_name_2_param_prefix = {'NONBON':'n' , 'BOND':'b', 'ANGL':'a', 'DIHE':'t', 'IMPR':'i'}
|
|
91
|
+
sec_name_2_param_index = dict((sn, 1) for sn in sec_names)
|
|
92
|
+
# Tags that will be used in the FFXML for these (same order)
|
|
93
|
+
force_tags = ['Atom', 'Bond', 'Angle', 'Improper', 'Proper']
|
|
94
|
+
# Force names in the FFXML (same order)
|
|
95
|
+
force_sections = ['vdW', 'Bonds', 'Angles', 'ImproperTorsions', 'ProperTorsions']
|
|
96
|
+
sec_name_2_force_tag = dict((sn, t) for sn, t in zip(sec_names, force_tags))
|
|
97
|
+
sec_name_2_force_section = dict((sn, fs) for sn, fs in zip(sec_names, force_sections))
|
|
98
|
+
|
|
99
|
+
date = None
|
|
100
|
+
author = None
|
|
101
|
+
for line in text:
|
|
102
|
+
#while ct < len(text):
|
|
103
|
+
#line = text[ct]
|
|
104
|
+
linesp = line.split()
|
|
105
|
+
|
|
106
|
+
# Skip lines starting with comment or which are blank
|
|
107
|
+
if line[0]=='#' or len(linesp) < 1:
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
# Check first entry to see if it's a section name, if so initialize storage
|
|
111
|
+
if linesp[0] in sec_names:
|
|
112
|
+
this_sec = linesp[0]
|
|
113
|
+
sections[this_sec] = []
|
|
114
|
+
|
|
115
|
+
elif linesp[0] in ['DATE', 'AUTHOR']:
|
|
116
|
+
this_sec = linesp[0]
|
|
117
|
+
# Otherwise store
|
|
118
|
+
else:
|
|
119
|
+
if this_sec == 'DATE':
|
|
120
|
+
date = line.strip()
|
|
121
|
+
elif this_sec == 'AUTHOR':
|
|
122
|
+
author = line.strip()
|
|
123
|
+
else:
|
|
124
|
+
sections[this_sec].append(line)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
parameter_lists = {}
|
|
128
|
+
|
|
129
|
+
# Use functions to parse sections from target file and add parameters to force field
|
|
130
|
+
for (sec_idx, sec_name) in enumerate(sec_names):
|
|
131
|
+
param_list = []
|
|
132
|
+
# sections[sec_name] = []
|
|
133
|
+
for line in sections[sec_name]:
|
|
134
|
+
# Parse line for parameters
|
|
135
|
+
if sec_name=='NONBON':
|
|
136
|
+
param = _parse_nonbon_line(line)
|
|
137
|
+
elif sec_name=='BOND':
|
|
138
|
+
param = _parse_bond_line(line)
|
|
139
|
+
elif sec_name=='DIHE':
|
|
140
|
+
param = _parse_dihe_line(line)
|
|
141
|
+
elif sec_name=='IMPR':
|
|
142
|
+
param = _parse_impr_line(line)
|
|
143
|
+
elif sec_name=='ANGL':
|
|
144
|
+
param = _parse_angl_line(line)
|
|
145
|
+
|
|
146
|
+
# Add parameter ID
|
|
147
|
+
param_prefix = sec_name_2_param_prefix[sec_name]
|
|
148
|
+
param_index = sec_name_2_param_index[sec_name]
|
|
149
|
+
param['id'] = param_prefix + str( param_index )
|
|
150
|
+
|
|
151
|
+
# If we're dealing with a simple parameter, just append it to the list
|
|
152
|
+
if not (sec_name in ['IMPR', 'DIHE']):
|
|
153
|
+
param_list.append(param)
|
|
154
|
+
# Increment parameter index
|
|
155
|
+
sec_name_2_param_index[sec_name] = sec_name_2_param_index[sec_name] + 1
|
|
156
|
+
|
|
157
|
+
# If we're dealing with a potentially multi-term parameter, check if this SMIRKS is already in the list
|
|
158
|
+
else:
|
|
159
|
+
param_matched = False
|
|
160
|
+
for existing_param in param_list:
|
|
161
|
+
if existing_param['smirks'] != param['smirks']:
|
|
162
|
+
continue
|
|
163
|
+
param_matched = True
|
|
164
|
+
# Find the lowest unoccupied torsion term index
|
|
165
|
+
term_index = 1
|
|
166
|
+
while f'k{term_index}' in existing_param:
|
|
167
|
+
term_index += 1
|
|
168
|
+
existing_param[f'k{term_index}'] = param['k1']
|
|
169
|
+
existing_param[f'phase{term_index}'] = param['phase1']
|
|
170
|
+
existing_param[f'periodicity{term_index}'] = param['periodicity1']
|
|
171
|
+
existing_param[f'idivf{term_index}'] = param['idivf1']
|
|
172
|
+
break
|
|
173
|
+
|
|
174
|
+
# If the SMIRKS isn't already known, initialize this as a new parameter, since it could be the
|
|
175
|
+
# first term of a multiterm torsion
|
|
176
|
+
if not(param_matched):
|
|
177
|
+
param_list.append(param)
|
|
178
|
+
# Increment parameter index ONLY for the first term of a torsion that's found.
|
|
179
|
+
sec_name_2_param_index[sec_name] = sec_name_2_param_index[sec_name] + 1
|
|
180
|
+
|
|
181
|
+
force_section = sec_name_2_force_section[sec_name]
|
|
182
|
+
force_tag = sec_name_2_force_tag[sec_name]
|
|
183
|
+
parameter_lists[force_section] = {force_tag: param_list.copy()}
|
|
184
|
+
|
|
185
|
+
return parameter_lists, author, date
|
|
186
|
+
|
|
187
|
+
# Main conversion functionality
|
|
188
|
+
def convert_frcmod_to_ffxml( infile, inxml, outxml ):
|
|
189
|
+
"""Convert a modified AMBER frcmod (with SMIRKS replacing atom types) to SMIRNOFF ffxml format by inserting parameters into a template ffxml file.
|
|
190
|
+
|
|
191
|
+
Parameters
|
|
192
|
+
----------
|
|
193
|
+
infile : str
|
|
194
|
+
File name of input SMIRKS-ified frcmod file containing parameters
|
|
195
|
+
inxml : str
|
|
196
|
+
File name of template SMIRNOFF FFXML file into which to insert these parameters.
|
|
197
|
+
outxml : str
|
|
198
|
+
File name of resulting output SMIRNOFF FFXML
|
|
199
|
+
|
|
200
|
+
Notes:
|
|
201
|
+
-------
|
|
202
|
+
Input XML file will normally be the template of a SMIRNOFF XML file without any parameters present (but with requisite force types already specified).
|
|
203
|
+
"""
|
|
204
|
+
from openff.toolkit.typing.engines.smirnoff import XMLParameterIOHandler
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
io_handler = XMLParameterIOHandler()
|
|
209
|
+
smirnoff_data = io_handler.parse_file(inxml)
|
|
210
|
+
parameter_lists, author, date = parse_frcmod(infile)
|
|
211
|
+
for section_tag in parameter_lists:
|
|
212
|
+
# Nest the actual parameter lists one level deeper, by their parameter_list_tag (eg Bonds > Bond > List)
|
|
213
|
+
parameter_list_tag = list(parameter_lists[section_tag].keys())[0]
|
|
214
|
+
smirnoff_data['SMIRNOFF'][section_tag][parameter_list_tag] = parameter_lists[section_tag][parameter_list_tag]
|
|
215
|
+
ff=ForceField()
|
|
216
|
+
ff._load_smirnoff_data(smirnoff_data)
|
|
217
|
+
print(ff.to_string())
|
|
218
|
+
|
|
219
|
+
# TODO: Add author and date
|
|
220
|
+
|
|
221
|
+
ff.to_file(outxml, io_format='XML')
|
|
222
|
+
# # Write SMIRNOFF XML file
|
|
223
|
+
# ff.writeFile(outxml)
|
|
224
|
+
#
|
|
225
|
+
# # Roundtrip to fix formatting (for some reason etree won't format it properly on first write after modification)
|
|
226
|
+
# tmp = ForceField(outxml)
|
|
227
|
+
# tmp.writeFile(outxml)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
if __name__=="__main__":
|
|
231
|
+
from optparse import OptionParser
|
|
232
|
+
usage_string="""\
|
|
233
|
+
Convert specified SMIRKS-ified AMBER frcmod file into SMIRNOFF FFXML format, inserting converted parameters into a template FFXML file and writing to a new output file.
|
|
234
|
+
|
|
235
|
+
usage: convert_frcmod_0.2.py --frcmod test.frcmod --template template.offxml --xml test.offxml
|
|
236
|
+
"""
|
|
237
|
+
parser = OptionParser(usage=usage_string)
|
|
238
|
+
|
|
239
|
+
parser.add_option('-f', '--frcmod', type = "string", dest='infile', default = None, action="store", help="Name of input smirks-ified frcmod file.")
|
|
240
|
+
parser.add_option('-t', '--template', type="string", dest='inxml', default = None, action ="store", help="Name of template SMIRNOFF offxml file.")
|
|
241
|
+
parser.add_option('-o', '--xml', type="string", dest='outxml', default =None, action="store", help="Name of output SMIRNOFF offxml file.")
|
|
242
|
+
(options,args) = parser.parse_args()
|
|
243
|
+
|
|
244
|
+
if (options.infile is None) or (options.inxml is None) or (options.outxml is None):
|
|
245
|
+
parser.print_help()
|
|
246
|
+
parser.error("Input frcmod and template files and output FFXML file must be specified.")
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
convert_frcmod_to_ffxml( options.infile, options.inxml, options.outxml )
|