Пример #1
0
 def parse(self):
     """
     DOCME
     """
     super(RTFFile, self).parse()
     self._parse_mass()
     self._parse_decl()
     self._parse_defa()
     self._parse_auto()
     iterator = ( line for line in self.body if not line.startswith('!') )
     iterator = paragraphs(logicalLines(iterator), self._sections)
     self.resi = {}
     self.pres = {}
     self._wtf = []
     for taco in iterator:
         if taco[0][:4] == 'resi':
             tmp = taco[0].split()[1]
             self.resi[tmp] = TopRes(taco)
         elif taco[0][:4] == 'pres':
             tmp = taco[0].split()[1]
             self.pres[tmp] = TopRes(taco)
         else:
             self._wtf.append(taco)
     self.chemResiDict = dict(( (k, v.chemDict) for k, v in self.resi.iteritems() ))
     self.chemPresDict = dict(( (k, v.chemDict) for k, v in self.pres.iteritems() ))
     self.chargeResiDict = dict(( (k, v.chargeDict) for k, v in self.resi.iteritems() ))
     self.chargePresDict = dict(( (k, v.chargeDict) for k, v in self.pres.iteritems() ))
Пример #2
0
 def __init__(self, arg):
     super(TopRes, self).__init__()
     tmp1 = []
     tmp2 = []
     for line in cleanStrings(arg, CC='!'):
         if line.startswith(('group', 'atom')):
             tmp1.append(line) # atom data
         else:
             tmp2.append(line) # everything else
     # turn tmp1 into a list
     self.groups = []
     for group in paragraphs(tmp1, ['grou']):
         self.groups.append([ tuple(line.split()[1:]) for line in group[1:] ])
     self.atoms = flatten(self.groups, ltypes=list)
     # turn tmp2 into a dict
     meta = {}
     for line in tmp2:
         key = line.split()[0]
         value = line.split(key)[1].lstrip()
         if key not in meta.keys():
             meta[key] = [value]
         else:
             meta[key].append(value)
     self.meta = meta
     # dicts
     self.chemDict = dict(( line[:2] for line in self.atoms ))
     self.chargeDict = dict(( [line[0], float(line[2])] for line in self.atoms ))
Пример #3
0
    def parse(self):
        super(PRMFile, self).parse()
        iterator = ( line for line in self.body if not line.startswith('!') )
        iterator = paragraphs(logicalLines(iterator), self._sections)
        for taco in iterator:
            try:
                if taco[0][:4] in self._sections:
                    self.cmd[taco[0][:4]] = taco[0]
                    self.prm[taco[0][:4]] = taco[1:]
                else:
                    self.comments.append(taco)
            except IndexError:
                pass

        # discard empties
        tmp = []
        for key, value in self.prm.iteritems():
            if not value:
                tmp.append(key)
        for key in tmp:
            try:
                del self.cmd[key]
            except KeyError:
                pass
            try:
                del self.prm[key]
            except KeyError:
                pass

        # rename sections
        def rename(old, new):
            if old in self.cmd.keys():
                self.cmd[new] = self.cmd[old]
                del self.cmd[old]
                self.prm[new] = self.prm[old]
                del self.prm[old]
        rename('thet', 'angl')
        rename('phi', 'dihe')
        rename('imph', 'impr')
        rename('nonb', 'nbon')

        # parse sections
        self._parse('atom', MassPRM)
        self._parse('bond', BondPRM)
        self._parse('angl', AnglePRM)
        self._parse('dihe', DihedralPRM)
        self._parse('impr', ImproperPRM)
        self._parse('nbon', NonBondPRM)
        self._parse('nbfi', NBFixPRM)
        # self._parse('hbon', HBondPRM) TODO -- implement HBondPRM objects in lib.toppar
        self._parse_cmap()
Пример #4
0
 def _build_models(self):
     """
     Parse the crd section, and load the coordinates into :class:`Mol`
     objects, one :class:`Mol` object per model section in the .pdb file.
     """
     models = paragraphs(self.crd, splitter=["model"])
     for model in models:
         if model[0].startswith("model"):
             modelNum = int(model[0].split()[1])
         else:
             modelNum = 0
         iterator = (
             Atom(text=line, informat=self.inFormat, index=i, autofix=self._autoFix)
             for i, line in enumerate(model)
             if line.startswith(("atom", "hetatm"))
         )
         self._mols["model%02d" % modelNum] = Mol(
             iterable=iterator, name="model%d" % modelNum, code=self.code, autofix=True
         )
Пример #5
0
def getProp(iterable, *props, **kwargs):
    """
    Returns a dictionary whose keys are the requested properties, and
    whose values are list(prop(t)).  Two key/value pairs are created
    per property: propX and propX_time.

    Usage: getProp(iterable,props*)
    Example:
    >>> getProp(open('charmm.out'),'averener','dynavdw')
    
    Each prop is of the form prefixsuffix, for example 'avertote'

    Valid prefixes are:
        ['dyna','aver','fluc','lave','lflc']

    Valid suffixes are:
        ['ener','hbon','volu','dihe','virk','vire','hfct','tote',
        'totk','presse','pressi','ehfc','asp','hfck','step','user',
        'urey','grms','impr','elec','vdw','temp','angl','time','viri',
        'bond']

    Valid kwargs:
        `stopIter` = int
    """
    props = [prop.lower() for prop in props]
    assert len(props) >= 1
    # Make sure properties are valid
    propList = []
    for prop in props:
        propList.append(parse_prop(prop))
    # kwargs
    if "stopIter" in kwargs.keys():
        stopIter = int(kwargs["stopIter"])
    else:
        stopIter = None
    # Initialize Lists
    outDict = {}
    for prop in propList:
        outDict["%s_time" % prop[0]] = []
        outDict[prop[0]] = []
    stepIterator = paragraphs(iterable, ["DYNA>", " DYNA>"])
    stepIterator.next()  # Discard Header
    stepIterator.next()  # Discard Step 0
    # Do Work
    for i, step in enumerate(stepIterator):
        if stopIter:
            if i >= stopIter:
                return outDict
        subSteps = paragraphs(step, [" ----------"])
        for subStep in subSteps:
            # Strip extraneous lines
            tmp = [line for line in subStep if not line.startswith(" ")]
            # Ignore empty blocks
            if tmp:
                # Ignore label block
                if tmp[0].startswith("AVER DYN"):
                    continue
                tmpSuffix = tmp[0][0:4].lower()
                for prop in propList:
                    if prop[1] == tmpSuffix:
                        lineNum, start, stop = propSuffixes[prop[2]]
                        outDict["%s_time" % prop[0]].append(i + 1)
                        outDict[prop[0]].append(float(tmp[lineNum][start:stop]))
    return outDict