Skip to content

Commit 14c2c8c

Browse files
edits to foyer tutorial
1 parent d71360c commit 14c2c8c

9 files changed

+554
-68
lines changed

foyer-overview.ipynb

+91-22
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
{
3232
"cell_type": "code",
33-
"execution_count": 1,
33+
"execution_count": 4,
3434
"metadata": {},
3535
"outputs": [
3636
{
@@ -99,7 +99,6 @@
9999
}
100100
],
101101
"source": [
102-
"###probably should change this to the PFA one\n",
103102
"!cat utils/oplsaa-alcohol.xml"
104103
]
105104
},
@@ -115,9 +114,8 @@
115114
"\n",
116115
"Consider defining the chemical context of the atoms in a methane molecule ($CH_4$) using SMARTS. The first thing to note is that there are multiple valid SMARTS that could describe the atom. \n",
117116
"- For example, the simplest way to describe the carbon atom in methane would be ```[C]```. \n",
118-
"- While in some cases such a simple definition may be sufficient, typically we wish to also define the number of bond, e.g., ```[C;X4]```. Note, ```;``` represents ```AND```, thus stating that the atom is a carbon with 4 bonds. \n",
119-
"- Often it is useful to further define the identity of those bonds. In this case, ```[C;X4](H)(H)(H)(H)```. \n",
120-
" "
117+
"- While in some cases such a simple definition may be sufficient, typically we wish to also define the number of bond, e.g., ```[C;X4]```. Note, ```;``` represents ```AND```, thus stating that the atom is a carbon AND it has 4 bonds. \n",
118+
"- Often it is useful to further define the identity of those bonds. In this case, ```[C;X4](H)(H)(H)(H)```. "
121119
]
122120
},
123121
{
@@ -126,24 +124,107 @@
126124
"source": [
127125
"### Exercise 1\n",
128126
"\n",
129-
"Modify the \"forcefield_exercise1.xml\" file to define SMARTS strings to define atomtypes for simple linear alkanes, for our fictious forcefield \"mosdef_ff\". \n",
127+
"Modify the \"mff_test1.xml\" file to define SMARTS strings to define atomtypes for simple linear alkanes, for our fictious forcefield \"mosdef_ff\". \n",
130128
"Here, the atom types for \"mosdef_ff\" are:\n",
131129
"\n",
132130
"* `mff_0`: carbon in methane (CH_4)\n",
133131
"* `mff_1`: carbon in a terminal methyl group of a linear chain (-CH_3)\n",
134132
"* `mff_2`: carbon in a middle methyl group of a linear chain (-CH_2-)\n",
135133
"* `mff_3`: a hydrogen atom\n",
136134
"\n",
137-
"After defining the appropriate SMARTS strings, run the test suite to ensure you did it correctly"
135+
"After defining the appropriate SMARTS strings, run the test suite to ensure you did it correctly. These use pytest to compare the output of your forcefield to the atom types listed in known mol2 files for methane, ethane, and propane. "
138136
]
139137
},
140138
{
141139
"cell_type": "code",
142-
"execution_count": null,
140+
"execution_count": 8,
143141
"metadata": {},
144-
"outputs": [],
142+
"outputs": [
143+
{
144+
"name": "stdout",
145+
"output_type": "stream",
146+
"text": [
147+
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
148+
"platform darwin -- Python 3.6.7, pytest-4.3.0, py-1.7.0, pluggy-0.8.0 -- /Users/cri/anaconda3/bin/python\n",
149+
"cachedir: .pytest_cache\n",
150+
"rootdir: /Users/cri/Projects/mosdef_tutorials, inifile:\n",
151+
"plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.1.3, arraydiff-0.3\n",
152+
"collected 1 item \u001b[0m\u001b[1m\n",
153+
"\n",
154+
"mff_test1/test_atomtyping.py::test_atomtyping[mol2_file0] \u001b[33mSKIPPED\u001b[0m\u001b[36m [100%]\u001b[0m\n",
155+
"\n",
156+
"\u001b[33m=============================== warnings summary ===============================\u001b[0m\n",
157+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
158+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\.'\n",
159+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
160+
"\n",
161+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
162+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
163+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\d'\n",
164+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
165+
"\n",
166+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
167+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
168+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\('\n",
169+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
170+
"\n",
171+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
172+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
173+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\)'\n",
174+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
175+
"\n",
176+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
177+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\+'\n",
178+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
179+
"\n",
180+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
181+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
182+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\*'\n",
183+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
184+
"\n",
185+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
186+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\#'\n",
187+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
188+
"\n",
189+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
190+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\['\n",
191+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
192+
"\n",
193+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
194+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\]'\n",
195+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
196+
"\n",
197+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
198+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\,'\n",
199+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
200+
"\n",
201+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
202+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\;'\n",
203+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
204+
"\n",
205+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
206+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\&'\n",
207+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
208+
"\n",
209+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
210+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\$'\n",
211+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
212+
"\n",
213+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
214+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\%'\n",
215+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
216+
"\n",
217+
"/Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758\n",
218+
" /Users/cri/anaconda3/lib/python3.6/site-packages/plyplus/plyplus.py:758: DeprecationWarning: invalid escape sequence '\\!'\n",
219+
" return codecs.getdecoder('unicode_escape')(token_value)[0]\n",
220+
"\n",
221+
"-- Docs: https://docs.pytest.org/en/latest/warnings.html\n",
222+
"\u001b[33m\u001b[1m==================== 1 skipped, 19 warnings in 1.16 seconds ====================\u001b[0m\n"
223+
]
224+
}
225+
],
145226
"source": [
146-
"# !pytest -v "
227+
"!py.test -v --tb=line mff_test1/"
147228
]
148229
},
149230
{
@@ -309,18 +390,6 @@
309390
"display_name": "Python 3",
310391
"language": "python",
311392
"name": "python3"
312-
},
313-
"language_info": {
314-
"codemirror_mode": {
315-
"name": "ipython",
316-
"version": 3
317-
},
318-
"file_extension": ".py",
319-
"mimetype": "text/x-python",
320-
"name": "python",
321-
"nbconvert_exporter": "python",
322-
"pygments_lexer": "ipython3",
323-
"version": "3.5.5"
324393
}
325394
},
326395
"nbformat": 4,

mff_test1/.DS_Store

6 KB
Binary file not shown.
Binary file not shown.

mff_test1/mff_test1.xml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<ForceField>
2+
<AtomTypes>
3+
<Type name="mff_0" class="CT" element="C" mass="12.01100"
4+
def="[C;X4](H)(H)(H)H" desc="methane CH4" />
5+
<Type name="mff_1" class="CT" element="C" mass="12.01100"
6+
def="[C;X4](C)(H)(H)H" desc="alkane CH3" />
7+
<Type name="mff_2" class="CT" element="C" mass="12.01100"
8+
def="[C;X4](C)(C)(H)H" desc="alkane CH2" />
9+
<Type name="mff_3" class="HC" element="H" mass="1.00800"
10+
def="H[C;X4]" desc="alkane H" />
11+
</AtomTypes>
12+
<HarmonicBondForce>
13+
<Bond class1="CT" class2="CT" length="0.1529" k="224262.4"/>
14+
<Bond class1="CT" class2="HC" length="0.109" k="284512.0"/>
15+
</HarmonicBondForce>
16+
<HarmonicAngleForce>
17+
<Angle class1="CT" class2="CT" class3="CT" angle="1.966986067" k="488.273"/>
18+
<Angle class1="CT" class2="CT" class3="HC" angle="1.93207948196" k="313.8"/>
19+
<Angle class1="HC" class2="CT" class3="HC" angle="1.88146493365" k="276.144"/>
20+
</HarmonicAngleForce>
21+
<RBTorsionForce>
22+
<Proper class1="CT" class2="CT" class3="CT" class4="CT"
23+
c0="2.9288" c1="-1.4644" c2="0.2092" c3="-1.6736" c4="0.0" c5="0.0"/>
24+
<Proper class1="CT" class2="CT" class3="CT" class4="HC"
25+
c0="0.6276" c1="1.8828" c2="0.0" c3="-2.5104" c4="0.0" c5="0.0"/>
26+
<Proper class1="HC" class2="CT" class3="CT" class4="HC"
27+
c0="0.6276" c1="1.8828" c2="0.0" c3="-2.5104" c4="0.0" c5="0.0"/>
28+
</RBTorsionForce>
29+
<NonbondedForce coulomb14scale="0.5" lj14scale="0.5">
30+
<Atom type="mff_0" charge="-0.18" sigma="0.35" epsilon="0.276144"/>
31+
<Atom type="mff_1" charge="-0.12" sigma="0.35" epsilon="0.276144"/>
32+
<Atom type="mff_2" charge="0.06" sigma="0.25" epsilon="0.12552"/>
33+
<Atom type="mff_3" charge="-0.683" sigma="0.312" epsilon="0.71128"/>
34+
</NonbondedForce>
35+
</ForceField>

mff_test1/test_atomtyping.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from glob import glob
2+
3+
import parmed as pmd
4+
import pytest
5+
6+
from foyer import Forcefield
7+
from foyer.tests.utils import atomtype
8+
9+
MOL2_FILES = glob('test_molecules/*.mol2')
10+
FORCEFIELD_FILES = glob('*.xml')
11+
12+
FORCEFIELD = Forcefield(forcefield_files=FORCEFIELD_FILES)
13+
14+
@pytest.mark.parametrize('mol2_file', MOL2_FILES)
15+
def test_atomtyping(mol2_file):
16+
structure = pmd.load_file(mol2_file, structure=True)
17+
atomtype(structure, FORCEFIELD)
18+
19+

mff_test1/test_molecules/ethane.mol2

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@<TRIPOS>MOLECULE
2+
RES
3+
8 7 1 0 1
4+
SMALL
5+
USER_CHARGES
6+
@<TRIPOS>CRYSIN
7+
7.2000 9.2000 5.0000 90.0000 90.0000 90.0000 1 1
8+
@<TRIPOS>ATOM
9+
1 C 0.0000 0.0000 0.0000 mff_1 1 RES -0.120000
10+
2 H -1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
11+
3 H 1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
12+
4 C 0.0000 1.4000 0.0000 mff_1 1 RES -0.120000
13+
5 H -1.1000 1.4000 0.0000 mff_3 1 RES -0.683000
14+
6 H 1.1000 1.4000 -0.0000 mff_3 1 RES -0.683000
15+
7 H 0.0000 2.8000 0.0000 mff_3 1 RES -0.683000
16+
8 H 0.0000 -1.4000 -0.0000 mff_3 1 RES -0.683000
17+
@<TRIPOS>BOND
18+
1 1 3 1
19+
2 1 2 1
20+
3 4 5 1
21+
4 4 6 1
22+
5 4 1 1
23+
6 7 4 1
24+
7 8 1 1
25+
@<TRIPOS>SUBSTRUCTURE
26+
1 RES 1 RESIDUE 0 1 ROOT 0

mff_test1/test_molecules/methane.mol2

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@<TRIPOS>MOLECULE
2+
RES
3+
5 4 1 0 1
4+
SMALL
5+
USER_CHARGES
6+
@<TRIPOS>CRYSIN
7+
7.2000 7.8000 5.0000 90.0000 90.0000 90.0000 1 1
8+
@<TRIPOS>ATOM
9+
1 C 0.0000 0.0000 0.0000 mff_0 1 RES -0.180000
10+
2 H -1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
11+
3 H 1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
12+
4 H -0.0000 1.4000 0.0000 mff_3 1 RES -0.683000
13+
5 H 0.0000 -1.4000 -0.0000 mff_3 1 RES -0.683000
14+
@<TRIPOS>BOND
15+
1 1 5 1
16+
2 1 2 1
17+
3 1 3 1
18+
4 4 1 1
19+
@<TRIPOS>SUBSTRUCTURE
20+
1 RES 1 RESIDUE 0 1 ROOT 0

mff_test1/test_molecules/propane.mol2

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@<TRIPOS>MOLECULE
2+
RES
3+
11 10 1 0 1
4+
SMALL
5+
USER_CHARGES
6+
@<TRIPOS>CRYSIN
7+
7.2000 10.6000 5.0000 90.0000 90.0000 90.0000 1 1
8+
@<TRIPOS>ATOM
9+
1 C 0.0000 0.0000 0.0000 mff_1 1 RES -0.120000
10+
2 H -1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
11+
3 H 1.1000 0.0000 0.0000 mff_3 1 RES -0.683000
12+
4 C 0.0000 1.4000 0.0000 mff_2 1 RES 0.060000
13+
5 H -1.1000 1.4000 0.0000 mff_3 1 RES -0.683000
14+
6 H 1.1000 1.4000 -0.0000 mff_3 1 RES -0.683000
15+
7 C 0.0000 2.8000 0.0000 mff_1 1 RES -0.120000
16+
8 H -1.1000 2.8000 0.0000 mff_3 1 RES -0.683000
17+
9 H 1.1000 2.8000 -0.0000 mff_3 1 RES -0.683000
18+
10 H 0.0000 4.2000 0.0000 mff_3 1 RES -0.683000
19+
11 H 0.0000 -1.4000 -0.0000 mff_3 1 RES -0.683000
20+
@<TRIPOS>BOND
21+
1 1 3 1
22+
2 1 2 1
23+
3 4 7 1
24+
4 4 5 1
25+
5 4 1 1
26+
6 4 6 1
27+
7 7 9 1
28+
8 7 10 1
29+
9 7 8 1
30+
10 11 1 1
31+
@<TRIPOS>SUBSTRUCTURE
32+
1 RES 1 RESIDUE 0 1 ROOT 0

0 commit comments

Comments
 (0)