예제 #1
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 ))
예제 #2
0
파일: pdb.py 프로젝트: jo-sm/charmminglib
 def _partitions(self):
     """
     Partition the file into _header/_crd/_footer sections.
     """
     iterator = (line for line in cleanStrings(open(self.filename)))
     # Populate header
     self._header = []
     tmp = None
     for line in iterator:
         if line.startswith(("atom", "hetatm", "model")):
             tmp = line
             break
         else:
             self._header.append(line)
     # Populate coordinates
     if tmp is None:
         self._crd = []
     else:
         self._crd = [tmp]
     tmp = None
     for line in iterator:
         if not line.startswith(("atom", "anisou", "hetatm", "model", "ter", "endmdl")):
             tmp = line
             break
         else:
             self._crd.append(line)
     # Populate footer
     if tmp is None:
         self._footer = []
     else:
         self._footer = [tmp]
     for line in iterator:
         self._footer.append(line)
예제 #3
0
파일: mol2.py 프로젝트: jo-sm/charmminglib
    def _partition(self):
        inHeader = False
        inCrd = False
        inBonds = False

        iterator = ( line for line in cleanStrings(open(self.filename) ))

        self._header = []
        self._crd = []
        self._bondstext = []

        for line in iterator:

            if not line:
                continue

            if line.startswith('@<tripos>'):
                sectionName = line[9:].strip()
                if sectionName == 'molecule':
                    inHeader = True
                    inCrd = False
                    inBonds = False

                    if self._header:
                        raise('Multiple header sections')
                elif sectionName == 'atom':
                    inHeader = False
                    inCrd = True
                    inBonds = False
                elif sectionName == 'bond':
                    if not self._crd:
                        raise('')

                    inHeader = False
                    inCrd = False
                    inBonds = True
                else:
                    # Throw away other sections
                    inHeader = False
                    inCrd = False
                    inBonds = False
            else:
                if inHeader:
                    self._header.append(line)
                elif inCrd:
                    self._crd.append(line)
                elif inBonds:
                    self._bondstext.append(line)