Creating and modifying Topologies¶
PyGromosTools offers a wide variaty of tools and functions to assist in the creation and modification of specialized topologies.
In the following notebook we will demonstrate some of the functions and theire usage. These functions and workflows should work with all supported forcfields, but we will use OpenForceField due to the fact that it is independant of make_top and a Gromos++ installation.
[1]:
import os
from rdkit.Chem import AllChem
[2]:
from pygromos.files.gromos_system.gromos_system import Gromos_System
from pygromos.files.forcefield.openff import openff
from pygromos.files.topology.top import Top
Warning: Unable to load toolkit 'OpenEye Toolkit'. The Open Force Field Toolkit does not require the OpenEye Toolkits, and can use RDKit/AmberTools instead. However, if you have a valid license for the OpenEye Toolkits, consider installing them for faster performance and additional file format support: https://docs.eyesopen.com/toolkits/python/quickstart-python/linuxosx.html OpenEye offers free Toolkit licenses for academics: https://www.eyesopen.com/academic-licensing
[3]:
# setting the work directory
root_dir = os.path.abspath("../example_files/topo_tutorial/")
Automatic System generation and combining of topologies¶
In the first part of this notebbok we demonstrate some automatic tools to create and modifie topologies.
[4]:
# defining the forcefield we want to use. In case a Gromos system is used make sure to have a valid Gromos++ installation and define the gromos++ path in Gromos_System or add it to you Path.
ff = openff.OpenFF()
Found off: /home/mlehner/PyGromosTools/pygromos/data/ff/SMIRNOFF/openff_unconstrained-2.0.0.offxml
[5]:
# We define a molecule in RDKit. Note that this molecule could be modified in RDKit or read from sdf, pdb, ... files
mol = AllChem.MolFromSmiles("C1CCCCC1")
mol = AllChem.AddHs(mol)
AllChem.EmbedMolecule(mol)
[5]:
0
[6]:
# We define our Gromos_system. Note the option auto_convert=True to automatically genarte a valid topology from the molecule defined in mol and the forcefield defined in ff.
grosys = Gromos_System(work_folder=root_dir, system_name="test", forcefield=ff,
rdkitMol=mol, auto_convert=True)
Found off: /home/mlehner/PyGromosTools/pygromos/data/ff/SMIRNOFF/openff_unconstrained-2.0.0.offxml
[7]:
# The topology created in the last step printed
grosys.top.TITLE
[7]:
TITLE
name: hill_formula: C6H12
----------------------------------------
| created from OpenForceField topology |
| use Amber Block for OpenFF topology! |
----------------------------------------
>>> Generated with PyGromosTools (riniker group) <<<
END
After the automatic creation of this topology for a Cyclohexan molecule we could try to make a liquid topology. Therefore we want to have multiple copies of our topology in one single topology.
[8]:
# define a new, empty top
retTop=Top(in_value=None)
With the “+=” operator we can add multiple topologies to a single topology. Or multiply the topology in a for loop. This alows costum topologies for liquids. After the loop we can reasign the variable to our Gromos_System and check if the additional molecules were added.
[9]:
for _ in range(10):
retTop += grosys.top
grosys.top = retTop
[10]:
# we added 10 copies of the initial moleucle to retTop and our new topology now contains 10 molecules in the RESNAME block.
grosys.top.RESNAME
[10]:
RESNAME
10
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
END
[11]:
grosys.top.make_ordered()
We can also add different molecules in our system. For example we could add a Toluene to our Cyclohexane system.
[12]:
# create a topology for Toluene
tolTop = Gromos_System(work_folder=root_dir, system_name="TOL", in_smiles="c1ccccc1C", forcefield=ff, auto_convert=True).top
Found off: /home/mlehner/PyGromosTools/pygromos/data/ff/SMIRNOFF/openff_unconstrained-2.0.0.offxml
[13]:
# add the toluene topology to our main topology
grosys.top += tolTop
[14]:
tolTop.LJPARAMETERS.content[0].C6
[14]:
0.0025854006549356347
[15]:
# check if it was added properly
grosys.top.RESNAME
[15]:
RESNAME
11
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C6H12
C7H8
END
If many topologies should be added to a single topology the PyGromosTools version of com_top can be used which directly implements multipliers. Instead of for loops.
Manual topology modifications¶
In this second part of the notebook we demonstrate some functions to manually tweek topologies.
Like with any othe PyGromosTools file class we have the option to brute force rewrite blocks. However, this often requires advanced knowlede of the block structure. Except for a few simple cases like the TITLE block.
[16]:
grosys.top.add_block(blocktitle="TITLE", content=["This is a new Title"])
[17]:
grosys.top.make_ordered()
[18]:
grosys.top.TITLE
[18]:
TITLE
This is a new Title
>>> Generated with PyGromosTools (riniker group) <<<
END
For more complexe blocks PyGromosTools provides many functions to modify topologies. For example we could simply add a new soluteatom to the system. This would be relevant if you want to manually add a ion with very specific Nonbonded values to you system. These tools are vary powrful, but don’t do any sanity checks on the values or compatibility to your forcefields.
[19]:
# We add a ion named 'XX' with charge +1 and certain LJ-Parameters to the main topology
grosys.top.add_new_atom(PANM="XX", CG=1, C6=1e-3, C12=1e-6, verbose=True)
New Atomtype with LJ parameters added. IAC found as: 5
[20]:
# Check for the new Atomtype 'XX'
grosys.top.ATOMTYPENAME
[20]:
ATOMTYPENAME
5
n16
n2
n14
n7
XX
END
[21]:
grosys.top.SOLUTEATOM
[21]:
SOLUTEATOM
# NRP: number of solute atoms
196
# ATNM: atom number
# MRES: residue number
# PANM: atom name of solute atom
# IAC: integer (van der Waals) atom type code
# MASS: mass of solute atom
# CG: charge of solute atom
# CGC: charge group code (0 or 1)
# INE: number of excluded atoms
# INE14: number of 1-4 interactions
# ATNM MRES PANM IAC MASS CG CGC INE
# INE14
1 1 C1 1 12.01078 -0.0764 0 10 2 3 5 6 7 8
9 10 17 18
5 4 11 12 15 16
2 1 C2 1 12.01078 -0.0764 0 9 3 4 6 7 8 9
10 11 12
5 5 13 14 17 18
3 1 C3 1 12.01078 -0.0764 0 8 4 5 9 10 11 12
13 14
5 6 7 8 15 16
4 1 C4 1 12.01078 -0.0764 0 8 5 6 11 12 13 14
15 16
4 9 10 17 18
5 1 C5 1 12.01078 -0.0764 0 7 6 13 14 15 16 17
18
4 7 8 11 12
6 1 C6 1 12.01078 -0.0764 0 6 7 8 15 16 17 18
4 9 10 13 14
7 1 H1 2 1.007947 0.0382 0 1 8
4 9 10 17 18
8 1 H2 2 1.007947 0.0382 0 0
4 9 10 17 18
9 1 H3 2 1.007947 0.0382 0 1 10
2 11 12
10 1 H4 2 1.007947 0.0382 0 0
2 11 12
11 1 H5 2 1.007947 0.0382 0 1 12
2 13 14
12 1 H6 2 1.007947 0.0382 0 0
2 13 14
13 1 H7 2 1.007947 0.0382 0 1 14
2 15 16
14 1 H8 2 1.007947 0.0382 0 0
2 15 16
15 1 H9 2 1.007947 0.0382 0 1 16
2 17 18
16 1 H10 2 1.007947 0.0382 0 0
2 17 18
17 1 H11 2 1.007947 0.0382 0 1 18
0
18 1 H12 2 1.007947 0.0382 1 0
0
19 2 C1 1 12.01078 -0.0764 0 10 20 21 23 24 25 26
27 28 35 36
5 22 29 30 33 34
20 2 C2 1 12.01078 -0.0764 0 9 21 22 24 25 26 27
28 29 30
5 23 31 32 35 36
21 2 C3 1 12.01078 -0.0764 0 8 22 23 27 28 29 30
31 32
5 24 25 26 33 34
22 2 C4 1 12.01078 -0.0764 0 8 23 24 29 30 31 32
33 34
4 27 28 35 36
23 2 C5 1 12.01078 -0.0764 0 7 24 31 32 33 34 35
36
4 25 26 29 30
24 2 C6 1 12.01078 -0.0764 0 6 25 26 33 34 35 36
4 27 28 31 32
25 2 H1 2 1.007947 0.0382 0 1 26
4 27 28 35 36
26 2 H2 2 1.007947 0.0382 0 0
4 27 28 35 36
27 2 H3 2 1.007947 0.0382 0 1 28
2 29 30
28 2 H4 2 1.007947 0.0382 0 0
2 29 30
29 2 H5 2 1.007947 0.0382 0 1 30
2 31 32
30 2 H6 2 1.007947 0.0382 0 0
2 31 32
31 2 H7 2 1.007947 0.0382 0 1 32
2 33 34
32 2 H8 2 1.007947 0.0382 0 0
2 33 34
33 2 H9 2 1.007947 0.0382 0 1 34
2 35 36
34 2 H10 2 1.007947 0.0382 0 0
2 35 36
35 2 H11 2 1.007947 0.0382 0 1 36
0
36 2 H12 2 1.007947 0.0382 1 0
0
37 3 C1 1 12.01078 -0.0764 0 10 38 39 41 42 43 44
45 46 53 54
5 40 47 48 51 52
38 3 C2 1 12.01078 -0.0764 0 9 39 40 42 43 44 45
46 47 48
5 41 49 50 53 54
39 3 C3 1 12.01078 -0.0764 0 8 40 41 45 46 47 48
49 50
5 42 43 44 51 52
40 3 C4 1 12.01078 -0.0764 0 8 41 42 47 48 49 50
51 52
4 45 46 53 54
41 3 C5 1 12.01078 -0.0764 0 7 42 49 50 51 52 53
54
4 43 44 47 48
42 3 C6 1 12.01078 -0.0764 0 6 43 44 51 52 53 54
4 45 46 49 50
43 3 H1 2 1.007947 0.0382 0 1 44
4 45 46 53 54
44 3 H2 2 1.007947 0.0382 0 0
4 45 46 53 54
45 3 H3 2 1.007947 0.0382 0 1 46
2 47 48
46 3 H4 2 1.007947 0.0382 0 0
2 47 48
47 3 H5 2 1.007947 0.0382 0 1 48
2 49 50
48 3 H6 2 1.007947 0.0382 0 0
2 49 50
49 3 H7 2 1.007947 0.0382 0 1 50
2 51 52
50 3 H8 2 1.007947 0.0382 0 0
2 51 52
51 3 H9 2 1.007947 0.0382 0 1 52
2 53 54
52 3 H10 2 1.007947 0.0382 0 0
2 53 54
53 3 H11 2 1.007947 0.0382 0 1 54
0
54 3 H12 2 1.007947 0.0382 1 0
0
55 4 C1 1 12.01078 -0.0764 0 10 56 57 59 60 61 62
63 64 71 72
5 58 65 66 69 70
56 4 C2 1 12.01078 -0.0764 0 9 57 58 60 61 62 63
64 65 66
5 59 67 68 71 72
57 4 C3 1 12.01078 -0.0764 0 8 58 59 63 64 65 66
67 68
5 60 61 62 69 70
58 4 C4 1 12.01078 -0.0764 0 8 59 60 65 66 67 68
69 70
4 63 64 71 72
59 4 C5 1 12.01078 -0.0764 0 7 60 67 68 69 70 71
72
4 61 62 65 66
60 4 C6 1 12.01078 -0.0764 0 6 61 62 69 70 71 72
4 63 64 67 68
61 4 H1 2 1.007947 0.0382 0 1 62
4 63 64 71 72
62 4 H2 2 1.007947 0.0382 0 0
4 63 64 71 72
63 4 H3 2 1.007947 0.0382 0 1 64
2 65 66
64 4 H4 2 1.007947 0.0382 0 0
2 65 66
65 4 H5 2 1.007947 0.0382 0 1 66
2 67 68
66 4 H6 2 1.007947 0.0382 0 0
2 67 68
67 4 H7 2 1.007947 0.0382 0 1 68
2 69 70
68 4 H8 2 1.007947 0.0382 0 0
2 69 70
69 4 H9 2 1.007947 0.0382 0 1 70
2 71 72
70 4 H10 2 1.007947 0.0382 0 0
2 71 72
71 4 H11 2 1.007947 0.0382 0 1 72
0
72 4 H12 2 1.007947 0.0382 1 0
0
73 5 C1 1 12.01078 -0.0764 0 10 74 75 77 78 79 80
81 82 89 90
5 76 83 84 87 88
74 5 C2 1 12.01078 -0.0764 0 9 75 76 78 79 80 81
82 83 84
5 77 85 86 89 90
75 5 C3 1 12.01078 -0.0764 0 8 76 77 81 82 83 84
85 86
5 78 79 80 87 88
76 5 C4 1 12.01078 -0.0764 0 8 77 78 83 84 85 86
87 88
4 81 82 89 90
77 5 C5 1 12.01078 -0.0764 0 7 78 85 86 87 88 89
90
4 79 80 83 84
78 5 C6 1 12.01078 -0.0764 0 6 79 80 87 88 89 90
4 81 82 85 86
79 5 H1 2 1.007947 0.0382 0 1 80
4 81 82 89 90
80 5 H2 2 1.007947 0.0382 0 0
4 81 82 89 90
81 5 H3 2 1.007947 0.0382 0 1 82
2 83 84
82 5 H4 2 1.007947 0.0382 0 0
2 83 84
83 5 H5 2 1.007947 0.0382 0 1 84
2 85 86
84 5 H6 2 1.007947 0.0382 0 0
2 85 86
85 5 H7 2 1.007947 0.0382 0 1 86
2 87 88
86 5 H8 2 1.007947 0.0382 0 0
2 87 88
87 5 H9 2 1.007947 0.0382 0 1 88
2 89 90
88 5 H10 2 1.007947 0.0382 0 0
2 89 90
89 5 H11 2 1.007947 0.0382 0 1 90
0
90 5 H12 2 1.007947 0.0382 1 0
0
91 6 C1 1 12.01078 -0.0764 0 10 92 93 95 96 97 98
99 100 107 108
5 94 101 102 105 106
92 6 C2 1 12.01078 -0.0764 0 9 93 94 96 97 98 99
100 101 102
5 95 103 104 107 108
93 6 C3 1 12.01078 -0.0764 0 8 94 95 99 100 101 102
103 104
5 96 97 98 105 106
94 6 C4 1 12.01078 -0.0764 0 8 95 96 101 102 103 104
105 106
4 99 100 107 108
95 6 C5 1 12.01078 -0.0764 0 7 96 103 104 105 106 107
108
4 97 98 101 102
96 6 C6 1 12.01078 -0.0764 0 6 97 98 105 106 107 108
4 99 100 103 104
97 6 H1 2 1.007947 0.0382 0 1 98
4 99 100 107 108
98 6 H2 2 1.007947 0.0382 0 0
4 99 100 107 108
99 6 H3 2 1.007947 0.0382 0 1 100
2 101 102
100 6 H4 2 1.007947 0.0382 0 0
2 101 102
101 6 H5 2 1.007947 0.0382 0 1 102
2 103 104
102 6 H6 2 1.007947 0.0382 0 0
2 103 104
103 6 H7 2 1.007947 0.0382 0 1 104
2 105 106
104 6 H8 2 1.007947 0.0382 0 0
2 105 106
105 6 H9 2 1.007947 0.0382 0 1 106
2 107 108
106 6 H10 2 1.007947 0.0382 0 0
2 107 108
107 6 H11 2 1.007947 0.0382 0 1 108
0
108 6 H12 2 1.007947 0.0382 1 0
0
109 7 C1 1 12.01078 -0.0764 0 10 110 111 113 114 115 116
117 118 125 126
5 112 119 120 123 124
110 7 C2 1 12.01078 -0.0764 0 9 111 112 114 115 116 117
118 119 120
5 113 121 122 125 126
111 7 C3 1 12.01078 -0.0764 0 8 112 113 117 118 119 120
121 122
5 114 115 116 123 124
112 7 C4 1 12.01078 -0.0764 0 8 113 114 119 120 121 122
123 124
4 117 118 125 126
113 7 C5 1 12.01078 -0.0764 0 7 114 121 122 123 124 125
126
4 115 116 119 120
114 7 C6 1 12.01078 -0.0764 0 6 115 116 123 124 125 126
4 117 118 121 122
115 7 H1 2 1.007947 0.0382 0 1 116
4 117 118 125 126
116 7 H2 2 1.007947 0.0382 0 0
4 117 118 125 126
117 7 H3 2 1.007947 0.0382 0 1 118
2 119 120
118 7 H4 2 1.007947 0.0382 0 0
2 119 120
119 7 H5 2 1.007947 0.0382 0 1 120
2 121 122
120 7 H6 2 1.007947 0.0382 0 0
2 121 122
121 7 H7 2 1.007947 0.0382 0 1 122
2 123 124
122 7 H8 2 1.007947 0.0382 0 0
2 123 124
123 7 H9 2 1.007947 0.0382 0 1 124
2 125 126
124 7 H10 2 1.007947 0.0382 0 0
2 125 126
125 7 H11 2 1.007947 0.0382 0 1 126
0
126 7 H12 2 1.007947 0.0382 1 0
0
127 8 C1 1 12.01078 -0.0764 0 10 128 129 131 132 133 134
135 136 143 144
5 130 137 138 141 142
128 8 C2 1 12.01078 -0.0764 0 9 129 130 132 133 134 135
136 137 138
5 131 139 140 143 144
129 8 C3 1 12.01078 -0.0764 0 8 130 131 135 136 137 138
139 140
5 132 133 134 141 142
130 8 C4 1 12.01078 -0.0764 0 8 131 132 137 138 139 140
141 142
4 135 136 143 144
131 8 C5 1 12.01078 -0.0764 0 7 132 139 140 141 142 143
144
4 133 134 137 138
132 8 C6 1 12.01078 -0.0764 0 6 133 134 141 142 143 144
4 135 136 139 140
133 8 H1 2 1.007947 0.0382 0 1 134
4 135 136 143 144
134 8 H2 2 1.007947 0.0382 0 0
4 135 136 143 144
135 8 H3 2 1.007947 0.0382 0 1 136
2 137 138
136 8 H4 2 1.007947 0.0382 0 0
2 137 138
137 8 H5 2 1.007947 0.0382 0 1 138
2 139 140
138 8 H6 2 1.007947 0.0382 0 0
2 139 140
139 8 H7 2 1.007947 0.0382 0 1 140
2 141 142
140 8 H8 2 1.007947 0.0382 0 0
2 141 142
141 8 H9 2 1.007947 0.0382 0 1 142
2 143 144
142 8 H10 2 1.007947 0.0382 0 0
2 143 144
143 8 H11 2 1.007947 0.0382 0 1 144
0
144 8 H12 2 1.007947 0.0382 1 0
0
145 9 C1 1 12.01078 -0.0764 0 10 146 147 149 150 151 152
153 154 161 162
5 148 155 156 159 160
146 9 C2 1 12.01078 -0.0764 0 9 147 148 150 151 152 153
154 155 156
5 149 157 158 161 162
147 9 C3 1 12.01078 -0.0764 0 8 148 149 153 154 155 156
157 158
5 150 151 152 159 160
148 9 C4 1 12.01078 -0.0764 0 8 149 150 155 156 157 158
159 160
4 153 154 161 162
149 9 C5 1 12.01078 -0.0764 0 7 150 157 158 159 160 161
162
4 151 152 155 156
150 9 C6 1 12.01078 -0.0764 0 6 151 152 159 160 161 162
4 153 154 157 158
151 9 H1 2 1.007947 0.0382 0 1 152
4 153 154 161 162
152 9 H2 2 1.007947 0.0382 0 0
4 153 154 161 162
153 9 H3 2 1.007947 0.0382 0 1 154
2 155 156
154 9 H4 2 1.007947 0.0382 0 0
2 155 156
155 9 H5 2 1.007947 0.0382 0 1 156
2 157 158
156 9 H6 2 1.007947 0.0382 0 0
2 157 158
157 9 H7 2 1.007947 0.0382 0 1 158
2 159 160
158 9 H8 2 1.007947 0.0382 0 0
2 159 160
159 9 H9 2 1.007947 0.0382 0 1 160
2 161 162
160 9 H10 2 1.007947 0.0382 0 0
2 161 162
161 9 H11 2 1.007947 0.0382 0 1 162
0
162 9 H12 2 1.007947 0.0382 1 0
0
163 10 C1 1 12.01078 -0.0764 0 10 164 165 167 168 169 170
171 172 179 180
5 166 173 174 177 178
164 10 C2 1 12.01078 -0.0764 0 9 165 166 168 169 170 171
172 173 174
5 167 175 176 179 180
165 10 C3 1 12.01078 -0.0764 0 8 166 167 171 172 173 174
175 176
5 168 169 170 177 178
166 10 C4 1 12.01078 -0.0764 0 8 167 168 173 174 175 176
177 178
4 171 172 179 180
167 10 C5 1 12.01078 -0.0764 0 7 168 175 176 177 178 179
180
4 169 170 173 174
168 10 C6 1 12.01078 -0.0764 0 6 169 170 177 178 179 180
4 171 172 175 176
169 10 H1 2 1.007947 0.0382 0 1 170
4 171 172 179 180
170 10 H2 2 1.007947 0.0382 0 0
4 171 172 179 180
171 10 H3 2 1.007947 0.0382 0 1 172
2 173 174
172 10 H4 2 1.007947 0.0382 0 0
2 173 174
173 10 H5 2 1.007947 0.0382 0 1 174
2 175 176
174 10 H6 2 1.007947 0.0382 0 0
2 175 176
175 10 H7 2 1.007947 0.0382 0 1 176
2 177 178
176 10 H8 2 1.007947 0.0382 0 0
2 177 178
177 10 H9 2 1.007947 0.0382 0 1 178
2 179 180
178 10 H10 2 1.007947 0.0382 0 0
2 179 180
179 10 H11 2 1.007947 0.0382 0 1 180
0
180 10 H12 2 1.007947 0.0382 1 0
0
181 11 C1 3 12.01078 -0.13099993333333335 0 7 182 183 185 186 187 188
189
6 184 190 192 193 194 195
182 11 C2 3 12.01078 -0.12699993333333334 0 6 183 184 186 188 189 190
3 185 187 191
183 11 C3 3 12.01078 -0.13499993333333335 0 5 184 185 189 190 191
3 186 188 192
184 11 C4 3 12.01078 -0.12699993333333334 0 5 185 186 190 191 192
2 187 189
185 11 C5 3 12.01078 -0.13099993333333335 0 4 186 187 191 192
5 188 190 193 194 195
186 11 C6 3 12.01078 -0.07729993333333333 0 6 187 188 192 193 194 195
2 189 191
187 11 C7 1 12.01078 -0.053799933333333334 0 3 193 194 195
2 188 192
188 11 H1 4 1.007947 0.13000006666666666 0 0
1 189
189 11 H2 4 1.007947 0.13000006666666666 0 0
1 190
190 11 H3 4 1.007947 0.13000006666666666 0 0
1 191
191 11 H4 4 1.007947 0.13000006666666666 0 0
1 192
192 11 H5 4 1.007947 0.13000006666666666 0 0
0
193 11 H6 2 1.007947 0.04403306666666667 0 2 194 195
0
194 11 H7 2 1.007947 0.04403306666666667 0 1 195
0
195 11 H8 2 1.007947 0.04403306666666667 1 0
0
196 12 XX 5 1.0 1 1 0
0
END
[22]:
grosys.rebase_files()
File imd is empty , can not be written!
/home/mlehner/PyGromosTools/pygromos/files/gromos_system/gromos_system.py:869: UserWarning: Did not change file path as its only promised None
warnings.warn("Did not change file path as its only promised " + str(file_obj.path))
[ ]: