ForceBalance API  1.3
Automated optimization of force fields and empirical potentials
custom_io.py
Go to the documentation of this file.
1 """ @package forcebalance.custom_io Custom force field parser.
2 
3 We take advantage of the sections in GROMACS and the 'interaction
4 type' concept, but these interactions are not supported in GROMACS;
5 rather, they are computed within our program.
6 
7 @author Lee-Ping Wang
8 @date 12/2011
9 """
10 
11 from re import match, sub
12 from forcebalance import BaseReader
13 
14 
15 cptypes = [None, 'CPGAUSS', 'CPEXPG', 'CPGEXP']
16 
17 ndtypes = [None]
18 
19 
20 fdict = {
21  'counterpoise' : cptypes }
22 
23 
24 pdict = {'CPGAUSS':{3:'A', 4:'B', 5:'C'},
25  'CPGEXP' :{3:'A', 4:'B', 5:'G', 6:'X'},
26  'CPEXPG' :{3:'A1', 4:'B', 5:'X0', 6:'A2'}
27  }
28 
29 class Gen_Reader(BaseReader):
30  """Finite state machine for parsing custom GROMACS force field files.
31 
32  This class is instantiated when we begin to read in a file. The
33  feed(line) method updates the state of the machine, giving it
34  information like the residue we're currently on, the nonbonded
35  interaction type, and the section that we're in. Using this
36  information we can look up the interaction type and parameter type
37  for building the parameter ID.
38 
39  """
40 
41  def __init__(self,fnm):
42  # Initialize the superclass. :)
43  super(Gen_Reader,self).__init__(fnm)
44 
45  self.sec = None
46 
47  self.pdict = pdict
48 
49  def feed(self, line):
50  """ Feed in a line.
51 
52  @param[in] line The line of data
53 
54  """
55  s = line.split()
56  atom = []
57  self.itype = None
58  self.ln += 1
59  # No sense in doing anything for an empty line or a comment line.
60  if len(s) == 0 or match('^;',line): return None, None
61  # Now go through all the cases.
62  if match('^\[.*\]',line):
63  # Makes a word like "atoms", "bonds" etc.
64  self.sec = sub('[\[\] \n]','',line)
65  elif self.sec == 'counterpoise':
66  self.itype = cptypes[int(s[2])]
67  atom = [s[0],s[1]]
68  elif self.sec == 'NDDO':
69  # NDDO hasn't been tested since the refactoring.
70  self.itype = '_'.join(['NDDO', s[0], s[1]])
71  else:
72  return [],"Confused"
73  if len(atom) > 1 and atom[0] > atom[-1]:
74  # Enforce a canonical ordering of the atom labels in a parameter ID
75  atom = atom[::-1]
76  self.suffix = ''.join(atom)
pdict
The parameter dictionary (defined in this file)
Definition: custom_io.py:49
def __init__(self, fnm)
Definition: custom_io.py:43
Finite state machine for parsing custom GROMACS force field files.
Definition: custom_io.py:41
def feed(self, line)
Feed in a line.
Definition: custom_io.py:57
sec
The current section that we're in.
Definition: custom_io.py:47