Skip to content

Instantly share code, notes, and snippets.

@mattwthompson
Created September 8, 2023 19:09
Show Gist options
  • Save mattwthompson/06211a98b5b51e369716fbf181377e8d to your computer and use it in GitHub Desktop.
Save mattwthompson/06211a98b5b51e369716fbf181377e8d to your computer and use it in GitHub Desktop.
LAMMPS vs. OpenMM parameters
import glob
import numpy
import openmm
from openff.toolkit import ForceField, Molecule
sage = ForceField("openff-2.1.0.offxml")
def get_lammps_charges(interchange) -> list[float]:
interchange.to_lammps("tmp.lammps")
atom_types: dict[str, list[float, float]] = dict()
charges: list[float] = list()
sigmas: list[float] = list()
epsilons: list[float] = list()
with open("tmp.lammps") as file:
read_charges = False
read_coeffs = False
for line in file:
if line in ("", "\n"):
continue
if line == "Pair Coeffs\n":
read_coeffs = True
continue
if line == "Bond Coeffs\n":
read_coeffs = False
continue
if line == "Atoms\n":
read_charges = True
continue
if line == "Bonds\n":
read_charges = False
continue
if read_coeffs:
atom_type, epsilon, sigma = line.split()
# nm, kJ/mol
atom_types[atom_type] = [float(sigma) * 0.1, float(epsilon) * 4.184]
if read_charges:
index, molecule_tag, atom_type, charge, x, y, z = line.split()
charges.append(float(charge))
sigmas.append(atom_types[atom_type][0])
epsilons.append(atom_types[atom_type][1])
return charges, sigmas, epsilons
def get_openmm_charges(interchange) -> list[float]:
system = interchange.to_openmm(combine_nonbonded_forces=True)
charges: list[float] = list()
sigmas: list[float] = list()
epsilons: list[float] = list()
for force in system.getForces():
if type(force) is openmm.NonbondedForce:
for i in range(force.getNumParticles()):
charge, sigma, epsilon = force.getParticleParameters(i)
charges.append(charge._value)
sigmas.append(sigma._value)
epsilons.append(epsilon._value)
return charges, sigmas, epsilons
raise Exception
for file in glob.glob("Topologies/*/*"):
molecule = Molecule.from_file(file, allow_undefined_stereo=True)
interchange = sage.create_interchange(
molecule.to_topology(),
charge_from_molecules=[molecule],
)
differences = [
numpy.mean(
numpy.abs(
numpy.asarray(get_openmm_charges(interchange)[i])
- numpy.asarray(get_lammps_charges(interchange)[i])
)
)
for i in range(3)
]
print(
f"{file}\n\tcharge: {differences[0]:.2e}\n\tsigma: {differences[1]:.2e}\n\tepsilon: {differences[2]:.2e}"
)
"""
Topologies/urethane/urethane_51.sdf
charge: 1.39e-09
sigma: 2.01e-09
epsilon: 2.39e-09
Warning: Internal CIP error: node limit reached for atom IDX: 136, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 250, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 364, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 478, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 592, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 706, NODES: 137788
Topologies/urethane/urethane_45.sdf
charge: 2.78e-09
sigma: 1.98e-09
epsilon: 2.74e-09
Topologies/urethane/urethane_44.sdf
charge: 2.94e-09
sigma: 2.08e-09
epsilon: 2.67e-09
Topologies/urethane/urethane_52.sdf
charge: 1.55e-09
sigma: 2.02e-09
epsilon: 2.34e-09
Topologies/urethane/urethane_6.sdf
charge: 2.39e-09
sigma: 2.09e-09
epsilon: 2.71e-09
Topologies/urethane/urethane_47.sdf
charge: 2.48e-09
sigma: 2.00e-09
epsilon: 2.08e-09
Topologies/urethane/urethane_2.sdf
charge: 1.18e-09
sigma: 2.08e-09
epsilon: 2.17e-09
Topologies/urethane/urethane_42.sdf
charge: 2.39e-09
sigma: 1.98e-09
epsilon: 2.61e-09
Topologies/urethane/urethane_1.sdf
charge: 2.22e-09
sigma: 1.98e-09
epsilon: 2.56e-09
Warning: Internal CIP error: node limit reached for atom IDX: 136, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 250, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 364, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 478, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 592, NODES: 137788
Warning: Internal CIP error: node limit reached for atom IDX: 706, NODES: 137788
Topologies/urethane/urethane_0.sdf
charge: 2.64e-09
sigma: 1.96e-09
epsilon: 2.23e-09
Topologies/urethane/urethane_41.sdf
charge: 8.61e-10
sigma: 2.09e-09
epsilon: 2.09e-09
Topologies/urethane/urethane_24.sdf
charge: 1.04e-09
sigma: 1.88e-09
epsilon: 2.24e-09
Topologies/urethane/urethane_35.sdf
charge: 2.69e-09
sigma: 2.00e-09
epsilon: 2.76e-09
Warning: Internal CIP error: node limit reached for atom IDX: 140, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 201, NODES: 135716
Warning: Internal CIP error: node limit reached for atom IDX: 258, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 319, NODES: 135716
Warning: Internal CIP error: node limit reached for atom IDX: 376, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 437, NODES: 135716
Warning: Internal CIP error: node limit reached for atom IDX: 494, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 555, NODES: 135716
Warning: Internal CIP error: node limit reached for atom IDX: 612, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 673, NODES: 135716
Warning: Internal CIP error: node limit reached for atom IDX: 730, NODES: 138716
Warning: Internal CIP error: node limit reached for atom IDX: 791, NODES: 135716
Topologies/urethane/urethane_22.sdf
charge: 2.27e-09
sigma: 1.96e-09
epsilon: 2.22e-09
Warning (not error because allow_undefined_stereo=True): OEMol has unspecified stereochemistry. oemol.GetTitle():
Problematic atoms are:
Atom atomic num: 7, name: , idx: 34, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 33, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 35, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 41, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 91, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 90, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 92, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 98, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 148, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 147, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 149, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 155, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 205, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 204, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 206, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 212, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 262, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 261, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 263, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 269, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 319, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 318, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 320, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 326, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 376, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 375, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 377, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 383, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 433, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 432, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 434, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 440, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 459, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 458, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 460, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 466, aromatic: False, chiral: False
Topologies/urethane/urethane_12.sdf
charge: 2.06e-09
sigma: 2.04e-09
epsilon: 2.53e-09
Topologies/urethane/urethane_10.sdf
charge: 1.26e-09
sigma: 2.13e-09
epsilon: 2.58e-09
Topologies/urethane/urethane_29.sdf
charge: 2.62e-09
sigma: 1.99e-09
epsilon: 2.46e-09
Topologies/urethane/urethane_15.sdf
charge: 1.04e-09
sigma: 2.06e-09
epsilon: 2.51e-09
Topologies/urethane/urethane_14.sdf
charge: 1.38e-09
sigma: 2.07e-09
epsilon: 2.17e-09
Topologies/urethane/urethane_17.sdf
charge: 2.41e-09
sigma: 1.98e-09
epsilon: 2.40e-09
Warning (not error because allow_undefined_stereo=True): OEMol has unspecified stereochemistry. oemol.GetTitle():
Problematic atoms are:
Atom atomic num: 7, name: , idx: 38, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 35, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 39, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 60, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 105, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 102, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 106, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 127, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 172, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 169, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 173, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 194, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 239, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 236, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 240, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 261, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 306, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 303, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 307, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 328, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 373, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 370, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 374, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 395, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 440, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 437, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 441, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 462, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 507, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 504, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 508, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 529, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 543, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 540, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 544, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 565, aromatic: False, chiral: False
Topologies/urethane/urethane_49.sdf
charge: 2.37e-09
sigma: 1.98e-09
epsilon: 3.59e-09
Topologies/urethane/urethane_8.sdf
charge: 1.11e-09
sigma: 1.99e-09
epsilon: 2.46e-09
Warning (not error because allow_undefined_stereo=True): OEMol has unspecified stereochemistry. oemol.GetTitle():
Problematic atoms are:
Atom atomic num: 7, name: , idx: 23, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 22, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 24, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 30, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 69, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 68, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 70, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 76, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 115, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 114, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 116, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 122, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 161, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 160, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 162, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 168, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 207, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 206, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 208, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 214, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 253, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 252, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 254, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 260, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 299, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 298, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 300, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 306, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 345, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 344, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 346, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 352, aromatic: False, chiral: False
Atom atomic num: 7, name: , idx: 371, aromatic: False, chiral: True with bonds:
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 370, aromatic: False, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 372, aromatic: True, chiral: False
bond order: 1, chiral: False to atom atomic num: 6, name: , idx: 378, aromatic: False, chiral: False
Topologies/urethane/urethane_9.sdf
charge: 1.39e-09
sigma: 1.98e-09
epsilon: 2.80e-09
Topologies/urethane/urethane_48.sdf
charge: 2.67e-09
sigma: 2.01e-09
epsilon: 2.27e-09
Topologies/NIPU/NIPU_11.sdf
charge: 1.72e-09
sigma: 1.89e-09
epsilon: 2.45e-09
Topologies/NIPU/NIPU_2.sdf
charge: 1.36e-09
sigma: 1.94e-09
epsilon: 2.62e-09
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment