File: forcefield.rst

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (685 lines) | stat: -rw-r--r-- 21,921 bytes parent folder | download | duplicates (2)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
Forcefields
================================================================================

.. currentmodule:: ost.mol.mm

The forcefields are a dump for interactions with their parameters, but also
for atom specific information or residue definitions in the form of a 
:class:`BuildingBlock`. Objects for modifying residues can be set in form of 
:class:`BlockModifier` or :class:`HydrogenConstructor`.
They're also involved in dealing with the naming mess we're observing in the molecular mechanics
community and contain definable renaming rules that can be applied on an
:class:`EntityHandle` for renaming from e.g. PDB standard to the forcefield
specific standard. The standard forcefields in OpenStructure are loaded from
the files provided by Gromacs and the "standard" naming is therefore the same.
This has implications for controlling the protonation states for histidine.
If you e.g. want to enforce a d-protonated histidine you have to name
it HISD. Further reading can be found in the 
`Gromacs Manual <http://www.gromacs.org/Documentation/Manual>`_ 

Loading the standard forcefields provided by OpenStructure
--------------------------------------------------------------------------------

.. function:: LoadCHARMMForcefield()

   Loads the CHARMM27 forcefield read from Gromacs
   
   :returns: The loaded :class:`Forcefield`


.. function:: LoadAMBERForcefield()

   Loads the AMBER03 forcefield read from Gromacs
   
   :returns: The loaded :class:`Forcefield`


Reading forcefields
--------------------------------------------------------------------------------

.. class:: FFReader(base_dir)

  The :class:`FFReader` builds up a :class:`Forcefield`, that gets updated with
  every call to the read functions. If the read files contain preprocessor 
  statements as they are used in Gromacs, they will be applied to all
  subsequent lines read in. Parsed preprocessor statements are:
  #include, #define, #ifdef, #ifndef, #else and #endif

  Note that this class is rather experimental. It has nevertheless been 
  thoroughly tested for loading the CHARMM and AMBER forcefields in the
  Gromacs format. The reader is capable of resolving the preprocessor statements
  as they are used in Gromacs.

  :param base_dir:      Base path of the reader.
                        All loaded files must be defined relative to this base 
                        path.

  :type base_dir:       :class:`str`

  .. method:: ReadGromacsForcefield()

    Searches and reads the forcefield.itp and atomtypes.atp files 
    in the **base_dir** given at initialization. All atom specific 
    informations and bonded as well as nonbonded forces are read 
    this way.

  .. method:: ReadResidueDatabase(basename)

    Searches and reads all files belonging the the residue database
    defined by **basename**. With *basename=aminoacids* this function
    searches and reads all files in the **base_dir** matching *aminoacids.x*
    where *x* is *.rtp .arn .hdb .n.tdb .c.tdb .vsd .r2b*.
    Only the rtp file is mandatory, all others are neglected if not present.

    :param basename:    Basename of residue database to be loaded

    :type basename:     :class:`str`

  .. method:: ReadITP(basename)

    Searches and reads the itp file in the **base_dir**. *basename=amazing_ion*
    would therefore load the file *amazing_ion.itp*

    :param basename:    Basename of itp file to be loaded

    :type basename:     :class:`str`

  .. method:: SetForcefield(forcefield)

    Resets reader internal forcefield. Everything read so far is lost,
    except the already read preprocessor statements.

    :param forcefield:  Forcefield to be set

    :type forcefield:   :class:`Forcefield`

  .. method:: GetForcefield()

    Get the forcefield with everything read so far.

    :returns: The reader internal :class:`Forcefield` 


  .. code-block:: python
    
    path = "path_to_gromacs/share/top/charmm27.ff"
    reader = FFReader(path)

    #read in the data given in forcefield.itp and atomtypes.atp
    reader.ReadGromacsForcefield()

    #we also want to read several residue databases
    reader.ReadResidueDatabase("aminoacids")
    reader.ReadResidueDatabase("rna")
    reader.ReadResidueDatabase("dna")

    #ions and water are also nice to have, they're stored in itp files
    reader.ReadITP("tip3p")
    reader.ReadITP("ions")

    #let's finally get the reader internal forcefield out
    ff = reader.GetForcefield()

    #there is also an amazing ion definition in some other directory
    new_reader = FFReader("path/to/directory/with/itp/files")

    #we want to modify the previously read forcefield
    new_reader.SetForcefield(ff)

    #and read the amazing ion definition from an itp file
    #note, that any previously defined preprocessor statements
    #from the previous reader are lost 
    new_reader.ReadITP("amazing_ion")

    #the new forcefield finally contains everything we need, lets
    #extract it and save it down
    ff = new_reader.GetForcefield()
    ff.Save("charmm_forcefield.dat")

Generating forcefields with Antechamber
--------------------------------------------------------------------------------

The :doc:`antechamber <antechamber>` submodule of mol.mm defines functions to use
Antechamber (from AmberTools) to automatically generate force field parameters
and load the results into :class:`~ost.mol.mm.Forcefield` objects.

The Forcefield Class
--------------------------------------------------------------------------------

.. currentmodule:: ost.mol.mm

.. class:: Forcefield


  .. method:: Save(filename)

    Dumps forcefield into a binary file on disk

    :param filename:    Filename of the saved forcefield

    :type filename:     :class:`str` 



  .. staticmethod:: Load(filename)

    reads in binary forcefield file

    :param filename:    Filename of the forcefield to be loaded

    :type filename:     :class:`str`

    :returns:           loaded :class:`Forcefield`

    :raises:            :class:`RuntimeError` when **filename** can't be found



  .. method:: AddBond(bond)

    :param bond:        Bond to be added

    :type bond:         :class:`Interaction`

    :raises:            :class:`RuntimeError` when given interaction has
                                              no bond specific FuncType



  .. method:: AddAngle(angle)

    :param angle:       Angle to be added

    :type angle:        :class:`Interaction`

    :raises:            :class:`RuntimeError` when given interaction has
                                              no angle specific FuncType


  .. method:: AddDihedral(dihedral)

    :param dihedral:    Dihedral to be added

    :type dihedral:     :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no dihedral specific FuncType


  .. method:: AddImproper(improper)

    :param improper:    Improper to be added

    :type improper:     :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no improper specific FuncType


  .. method:: AddCMap(cmap)

    :param cmap:        CMap to be added

    :type cmap:         :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no cmap specific FuncType


  .. method:: AddImplicitGenborn(gb)

    :param gb:          GB to be added

    :type gb:           :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no gb specific FuncType


  .. method:: AddLJ(lj)

    :param lj:          LJ to be added

    :type lj:           :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no lj specific FuncType


  .. method:: AddLJPair(lj_pair)

    :param lj_pair:     LJPair to be added

    :type lj_pair:      :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no lj_pair specific FuncType


  .. method:: AddConstraint(constraint)

    :param constraint:  Constraint to be added

    :type constraint:   :class:`Interaction`     

    :raises:            :class:`RuntimeError` when given interaction has
                                              no constraint specific FuncType


  .. method:: AddMass(type, mass)

    :param type:        Type of atom
    :param mass:        Its mass

    :type type:         :class:`str`
    :type mass:         :class:`float`

  .. method:: SetFudgeLJ(factor)

    :param factor:      Factor with which the 1,4 Lennard Jones term
                        should be dampened

    :type factor:       :class:`float`


  .. method:: SetFudgeQQ(factor)

    :param factor:      Factor with which the 1,4 electrostatic term
                        should be dampened

    :type factor:       :class:`float`


  .. method:: SetGenPairs(gen_pairs)

    :param gen_pairs:   If set to false, all 1,4 interactions must be set
                        with AddLJPair. The Lorentz-Berthelot rule gets
                        used otherwise. 

    :type gen_pairs:    :class:`bool`


  .. method:: AddResidueRenamingRule(name, ff_main_name, ff_n_ter_name, ff_c_ter_name, ff_two_ter_name)

    :param name:        Original name of the residue 
                        (e.g. PDB/Gromacs standard)
    :param ff_main_name: Forcefield specific residue name
    :param ff_n_ter_name: Forcefield specific name if the residue
                          is N-Terminal
    :param ff_c_ter_name: Forcefield specific name if the residue
                                       is C-Terminal
    :param ff_two_ter_name: Forcefield specific name if the residue
                            is N- and C-Terminal

    :type name:            :class:`str`
    :type ff_main_name:    :class:`str`
    :type ff_n_ter_name:   :class:`str`
    :type ff_c_ter_name:   :class:`str`
    :type ff_two_ter_name: :class:`str`



  .. method:: AddAtomRenamingRule(res_name, old_atom_name, new_atom_name)

    :param res_name:    Forcefield specific name of the residue the
                                     atom belongs to

    :param old_atom_name: Atom name in PDB/Gromacs standard

    :param new_atom_name: FF specific atom name

    :type res_name:      :class:`str`
    :type old_atom_name: :class:`str`
    :type new_atom_name: :class:`str`


  .. method:: AddBuildingBlock(name, block)

    :param name:        Name of residue this :class:`BuildingBlock` 
                        is supposed to be related to

    :param block:       BuildingBlock to be added

    :type block:        :class:`BuildingBlock`
    :type name:         :class:`str`


  .. method:: AddHydrogenConstructor(name, h_constructor)

    :param name:        Name of residue this 
                        :class:`HydrogenConstructor` 
                        is supposed to be related to

    :param h_constructor: HydrogenConstructor to be added

    :type name:          :class:`str`
    :type h_constructor: :class:`HydrogenConstructor`


  .. method:: AddBlockModifier(name, modifier)

    :param name:        Name of residue this 
                        :class:`BlockModifier` 
                        is supposed to be related to

    :param modifier:    BlockModifier to be added

    :type name:         :class:`str`
    :type modifier:     :class:`BlockModifier`


  .. method:: SetStandardCTer(res_name, ter_name)

    Setting a standard CTer influences the behaviour of the GetCTerModifier 
    function. If no specific block modifier is defined there, this is the
    one that gets returned.

    :param res_name:    Forcefield specific residue name this block 
                        modifier is supposed to be related to

    :param ter_name:    Name of the default c-terminal block 
                        modifier for this residue

    :type res_name:     :class:`str`
    :type ter_name:     :class:`str`


  .. method:: SetStandardNTer(res_name, ter_name)

    Setting a standard NTer incluences the behaviour of the GetNTerModifier 
    function. If no specific block modifier is defined there, this is the
    one that gets returned.

    :param res_name:    Forcefield specific residue name this block 
                        modifier is supposed to be related to

    :param ter_name:    Name of the default n-terminal block 
                        modifier for this residue

    :type res_name:     :class:`str`
    :type ter_name:     :class:`str`
    


  .. method:: AssignFFSpecificNames(ent,[,reverse = False])

    This function does the forcefield specific renaming magic. It takes
    the given :class:`EntityHandle` and applies the rules set in
    AddResidueRenamingRule and AddAtomRenamingRule.

    :param ent:         Entity to be renamed

    :param reverse:     If False, the function does the renaming
                        from PDB/Gromacs naming to the forcefield
                        specific naming.
                        If True, the opposite happens.

    :type ent:          :class:`EntityHandle`
    :type reverse:      :class:`bool`


  .. method:: GetBond(type1, type2)

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2

    :type type1:        :class:`str`
    :type type2:        :class:`str`

    :returns: an :class:`Interaction` with a bond FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found


  .. method:: GetAngle(type1, type2, type3)

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2
    :param type3:       Type of interacting particle 3

    :type type1:        :class:`str`
    :type type2:        :class:`str`
    :type type3:        :class:`str`

    :returns: an :class:`Interaction` with a angle FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found


  .. method:: GetDihedrals(type1, type2, type3, type4)

    Several dihedral definitions can be merged to one dihedral function.
    This function therefore returns a list. 
    In a first step all dihedrals matching the given types are gathered
    and returned.
    If no dihedrals can be found, the search continues by including
    wildcard characters in the atom types (X). All found dihedrals
    matching with all possible combinations of wildcards are then gathered
    and returned.

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2
    :param type3:       Type of interacting particle 3
    :param type4:       Type of interacting particle 4

    :type type1:        :class:`str`
    :type type2:        :class:`str`
    :type type3:        :class:`str`
    :type type4:        :class:`str`

    :returns: a :class:`list` of :class:`Interaction` objects with dihedral 
              FuncType matching given types

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found



  .. method:: GetImpropers(type1, type2, type3, type4)

    The same search strategy as in GetDihedrals is used to extract 
    the impropers.

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2
    :param type3:       Type of interacting particle 3
    :param type4:       Type of interacting particle 4

    :type type1:        :class:`str`
    :type type2:        :class:`str`
    :type type3:        :class:`str`
    :type type4:        :class:`str`

    :returns: a :class:`list` of :class:`Interaction` objects with improper
              FuncType matching given types

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found


  .. method:: GetCMap(type1, type2, type3, type4, type5)

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2
    :param type3:       Type of interacting particle 3
    :param type4:       Type of interacting particle 4
    :param type5:       Type of interacting particle 5

    :type type1:        :class:`str`
    :type type2:        :class:`str`
    :type type3:        :class:`str`
    :type type4:        :class:`str`
    :type type5:        :class:`str`

    :returns: an :class:`Interaction` with a cmap FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found


  .. method:: GetImplicitGenborn(type)

    :param type:        Type of particle

    :type type:         :class:`str`

    :returns: an :class:`Interaction` with a gb FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given type can be found


  .. method:: GetLJ(type)

    :param type:        Type of particle

    :type type:         :class:`str`

    :returns: an :class:`Interaction` with a lj FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given type can be found


  .. method:: GetLJ(type1, type2,[,pair=False])
    :noindex:

    :param type1:        Type of interacting particle 1
    :param type2:        Type of interacting particle 2
    :param pair:         If set to true, the interaction is
                         assumed to be a 1,4-interaction and
                         the set lj_pairs are first searched
                         for matches. In case of no success,
                         the function uses the Lorentz-Berthelot
                         rule to combine the sigma and epsilon 
                         parameters.
                         If set to false, the Lorentz-Berthelot
                         rule is applied directly.

    :type type1:        :class:`str`
    :type type2:        :class:`str`
    :type pair:         :class:`bool`


    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found
                                              or when pair is true and no 
                                              appropriate lj_pair is set 
                                              despite gen_pair flag being false.


  .. method:: GetConstraint(type1, type2)

    :param type1:       Type of interacting particle 1
    :param type2:       Type of interacting particle 2

    :type type1:        :class:`str`
    :type type2:        :class:`str`

    :returns: an :class:`Interaction` with a constraint FuncType

    :raises:            :class:`RuntimeError` when no :class:`Interaction`
                                              matching given types can be found


  .. method:: GetMass(type)

    :param type:        Type of particle

    :type type:         :class:`str`

    :returns:           :class:`float` - the mass

    :raises:            :class:`RuntimeError` if no mass has been set for this 
                        atom type


  .. method:: GetFudgeLJ()

    :returns:  :class:`float` - Factor with which the 1,4 Lennard Jones 
                term should be dampened

  .. method:: GetFudgeQQ()

    :returns:  :class:`float` - Factor with which the 1,4 
                electrostatic term should be dampened


  .. method:: GetAtomType(res_name, atom_name)

    :param res_name:    Forcefield specific residue name

    :param atom_name:   Forcefield specific atom name belonging
                        to that residue

    :type res_name:     :class:`str`
    :type atom_name:    :class:`str`

    :returns:           :class:`str` - atom type

    :raises:            :class:`RuntimeError` if forcefield has no such
                        :class:`BuildingBlock` or when atom is not present 
                        in that :class:`BuildingBlock`   


  .. method:: GetHydrogenConstructor(res_name)

    :param res_name:    Name of residue
    :type res_name:     :class:`str`

    :returns: :class:`HydrogenConstructor` for this name, invalid if it can't
              be found


  .. method:: GetBuildingBlock(res_name)

    :param res_name:    Name of residue
    :type res_name:     :class:`str`

    :returns:  :class:`BuildingBlock` for this name, invalid if it can't be 
               found

  .. method:: GetBuildingBlockNames()

    :returns:  :class:`list` of all building block names present in that 
               forcefield


  .. method:: GetBlockModifier(res_name)

    :param res_name:    Name of residue
    :type res_name:     :class:`str`

    :returns: :class:`BlockModifier` for this name, invalid if it can't
              be found


  .. method:: GetNTerModifier(res_name,[,ter_name=""])

    :param res_name:    Name of residue

    :param ter_name:    If not set, the ter_name
                        defined by SetStandardNTer gets used

    :type res_name:     :class:`str`
    :type ter_name:     :class:`str`


    :returns: :class:`BlockModifier` for this name, invalid if it can't
              be found


  .. method:: GetCTerModifier(name,[,ter_name=""])

    :param res_name:    Name of residue

    :param ter_name:    If not set, the ter_name
                        defined by SetStandardCTer gets used

    :type res_name:     :class:`str`
    :type ter_name:     :class:`str`

    :returns: :class:`BlockModifier` for this name, invalid if it can't
              be found