-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_issues.py
More file actions
142 lines (109 loc) · 4.19 KB
/
test_issues.py
File metadata and controls
142 lines (109 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""Tests reproducing specific issues that are otherwise uncategorized."""
import random
import numpy
import parmed
import pytest
from openff.toolkit import ForceField, Molecule, Quantity, Topology
from openff.utilities import get_data_file_path, skip_if_missing
from openff.interchange import Interchange
from openff.interchange._tests import MoleculeWithConformer, shuffle_topology
from openff.interchange.drivers import get_openmm_energies
from openff.interchange.packmol import pack_box
def test_issue_723():
force_field = ForceField("openff-2.1.0.offxml")
molecule = Molecule.from_smiles("C#N")
molecule.generate_conformers(n_conformers=1)
force_field.create_interchange(molecule.to_topology()).to_top("_x.top")
parmed.load_file("_x.top")
@pytest.mark.parametrize("pack", [True, False])
def test_issue_1022(pack):
topology = Topology.from_molecules(
[
MoleculeWithConformer.from_smiles(smi)
for smi in [
"CBr",
"O",
"O",
"O",
"[Na+]",
"[Cl-]",
]
],
)
topology.box_vectors = Quantity(numpy.eye(3) * 10.0, "nanometer")
if pack:
topology = pack_box(
molecules=[*topology.unique_molecules],
number_of_copies=[1, 3, 1, 1],
box_vectors=topology.box_vectors,
)
force_field = ForceField(
"openff-2.0.0.offxml",
get_data_file_path(
"example-sigma-hole-bromine.offxml",
"openff.interchange._tests.data",
),
)
interchange = force_field.create_interchange(topology)
interchange.to_top("tmp")
if pack:
for seed in random.sample(range(0, 10**10), 5):
# TODO: Compare GROMACS energies here as well
get_openmm_energies(interchange).compare(
get_openmm_energies(
shuffle_topology(
interchange,
force_field,
seed=seed,
),
),
tolerances={"Nonbonded": Quantity("1e-3 kilojoule_per_mole")},
)
@skip_if_missing("openmm")
def test_issue_1031():
import openmm.app
# just grab some small PDB file from the toolkit, doesn't need to be huge, just
# needs to include some relevant atom names
openmm_topology = openmm.app.PDBFile(
get_data_file_path(
"proteins/MainChain_HIE.pdb",
"openff.toolkit",
),
).topology
openmm_atom_names = {atom.name for atom in openmm_topology.atoms()}
interchange = Interchange.from_openmm(
system=openmm.app.ForceField(
"amber99sb.xml",
"tip3p.xml",
).createSystem(
openmm_topology,
nonbondedMethod=openmm.app.PME,
),
topology=openmm_topology,
)
openff_atom_names = {atom.name for atom in interchange.topology.atoms}
assert sorted(openmm_atom_names) == sorted(openff_atom_names)
# check a few atom names to ensure these didn't end up being empty sets
for atom_name in ("NE2", "H3", "HA", "CH3", "CA", "CB", "CE1"):
assert atom_name in openff_atom_names
def test_issue_1049():
pytest.importorskip("openmm")
topology = Topology.from_molecules(
[
Molecule.from_smiles("C"),
Molecule.from_smiles("O"),
Molecule.from_smiles("O"),
],
)
interchange = ForceField("openff-2.2.0.offxml", "opc.offxml").create_interchange(topology)
openmm_topology = interchange.to_openmm_topology()
openmm_system = interchange.to_openmm_system()
# the same index in system should also be a virtual site in the topology
for particle_index, particle in enumerate(openmm_topology.atoms()):
assert openmm_system.isVirtualSite(particle_index) == (particle.element is None), (
f"particle index {particle_index} is a virtual site in the system OR topology but not both"
)
def test_issue_1052(sage, ethanol):
"""Test that _SMIRNOFFElectrostaticsCollection.charges is populated."""
out = sage.create_interchange(ethanol.to_topology())
assert len(out["Electrostatics"].charges) > 0