5
5
import copy
6
6
import io
7
7
import re
8
- import warnings
9
8
import xml .etree .ElementTree as ET
10
9
from pathlib import Path
11
10
from xml .etree .ElementTree import tostring
20
19
from openmm .app .pdbfile import PDBFile
21
20
from openmm .unit import kelvin , picoseconds
22
21
from pymatgen .core import Element
23
- from pymatgen .io .openff import get_atom_map
22
+ from pymatgen .io .openff import coerce_formal_charges , get_atom_map
24
23
25
24
from atomate2 .openff .utils import create_mol_spec , merge_specs_by_name_and_smiles
26
25
from atomate2 .openmm .jobs .base import openmm_job
@@ -85,12 +84,8 @@ def increment_types(self, increment: str) -> None:
85
84
if type_stub in key :
86
85
element .attrib [key ] += increment
87
86
88
- def to_openff_molecule (self ) -> tk .Molecule :
87
+ def to_openff_molecule (self , template_molecule : tk . Molecule = None ) -> tk .Molecule :
89
88
"""Convert the XMLMoleculeFF to an openff_toolkit Molecule."""
90
- if sum (self .partial_charges ) > 1e-3 :
91
- # TODO: update message
92
- warnings .warn ("Formal charges not considered." , stacklevel = 1 )
93
-
94
89
p_table = {e .symbol : e .number for e in Element }
95
90
openff_mol = tk .Molecule ()
96
91
for atom in self .tree .getroot ().findall (".//Residues/Residue/Atom" ):
@@ -108,6 +103,9 @@ def to_openff_molecule(self) -> tk.Molecule:
108
103
109
104
openff_mol .partial_charges = self .partial_charges * unit .elementary_charge
110
105
106
+ if template_molecule :
107
+ openff_mol = coerce_formal_charges (openff_mol , template_molecule )
108
+
111
109
return openff_mol
112
110
113
111
@property
@@ -253,7 +251,7 @@ def generate_openmm_interchange(
253
251
254
252
for mol_spec , xml_mol in zip (mol_specs , xml_mols , strict = True ):
255
253
openff_mol = tk .Molecule .from_json (mol_spec .openff_mol )
256
- xml_openff_mol = xml_mol .to_openff_molecule ()
254
+ xml_openff_mol = xml_mol .to_openff_molecule (template_molecule = openff_mol )
257
255
is_isomorphic , _atom_map = get_atom_map (openff_mol , xml_openff_mol )
258
256
if not is_isomorphic :
259
257
raise ValueError (
0 commit comments