示例#1
0
 def _readImproperParameters(self, file):
     format = FortranFormat('A2,1X,A2,1X,A2,1X,A2,I4,3F15.2')
     while True:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name3 = _normalizeName(l[2])
         name4 = _normalizeName(l[3])
         if name1 == 'X':
             if name2 == 'X':
                 name1 = name3
                 name2 = name4
                 name3 = 'X'
                 name4 = 'X'
             else:
                 name1 = name3
                 name2, name3 = _sort(name2, name4)
                 name4 = 'X'
         else:
             name1, name2, name3, name4 = \
                    (name3, ) + _sort3(name1, name2, name4)
         p = AmberImproperParameters(self.atom_types[name1],
                                     self.atom_types[name2],
                                     self.atom_types[name3],
                                     self.atom_types[name4],
                                     l[4], l[5], l[6], l[7])
         if name4 == 'X':
             if name3 == 'X':
                 self.impropers_2[(name1, name2)] = p
             else:
                 self.impropers_1[(name1, name2, name3)] = p
         else:
             self.impropers[(name1, name2, name3, name4)] = p
示例#2
0
 def _readLJParameters(self, file, ljpar_set):
     format = FortranFormat('2X,A2,6X,3F10.6')
     while True:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name = _normalizeName(l[0])
         ljpar_set.addEntry(name, l[1], l[2], l[3])
示例#3
0
 def _readAtomTypes(self, file):
     format = FortranFormat('A2,1X,F10.2')
     while True:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name = _normalizeName(l[0])
         self.atom_types[name] = AmberAtomType(name, l[1])
 def _readLJParameters(self, file, ljpar_set):
     format = FortranFormat('2X,A2,6X,3F10.6')
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name = _normalizeName(l[0])
         ljpar_set.addEntry(name, l[1], l[2], l[3])
 def _readImproperParameters(self, file):
     format = FortranFormat('A2,1X,A2,1X,A2,1X,A2,I4,3F15.2')
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name3 = _normalizeName(l[2])
         name4 = _normalizeName(l[3])
         if name1 == 'X':
             if name2 == 'X':
                 name1 = name3
                 name2 = name4
                 name3 = 'X'
                 name4 = 'X'
             else:
                 name1 = name3
                 name2, name3 = _sort(name2, name4)
                 name4 = 'X'
         else:
             name1, name2, name3, name4 = \
                    (name3, ) + _sort3(name1, name2, name4)
         p = AmberImproperParameters(self.atom_types[name1],
                                     self.atom_types[name2],
                                     self.atom_types[name3],
                                     self.atom_types[name4], l[4], l[5],
                                     l[6], l[7])
         if name4 == 'X':
             if name3 == 'X':
                 self.impropers_2[(name1, name2)] = p
             else:
                 self.impropers_1[(name1, name2, name3)] = p
         else:
             self.impropers[(name1, name2, name3, name4)] = p
 def _readDihedralParameters(self, file):
     format = FortranFormat('A2,1X,A2,1X,A2,1X,A2,I4,3F15.2')
     append = None
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name3 = _normalizeName(l[2])
         name4 = _normalizeName(l[3])
         name1, name2, name3, name4 = _sort4(name1, name2, name3, name4)
         if append is not None:
             append.addTerm(l[4], l[5], l[6], l[7])
             if l[7] >= 0: append = None
         else:
             p = AmberDihedralParameters(self.atom_types[name1],
                                         self.atom_types[name2],
                                         self.atom_types[name3],
                                         self.atom_types[name4], l[4], l[5],
                                         l[6], l[7])
             if name1 == 'X' and name4 == 'X':
                 self.dihedrals_2[(name2, name3)] = p
             else:
                 self.dihedrals[(name1, name2, name3, name4)] = p
             if l[7] < 0: append = p
 def _readAtomTypes(self, file):
     format = FortranFormat('A2,1X,F10.2')
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name = _normalizeName(l[0])
         self.atom_types[name] = AmberAtomType(name, l[1])
示例#8
0
 def _readHbondParameters(self, file):
     format = FortranFormat('2X,A2,2X,A2,2X,2F10.2')
     while True:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name1, name2 = _sort(name1, name2)
         self.hbonds[(name1, name2)] = \
                             AmberHbondParameters(self.atom_types[name1],
                                                  self.atom_types[name2],
                                                  l[2], l[3])
 def _readHbondParameters(self, file):
     format = FortranFormat('2X,A2,2X,A2,2X,2F10.2')
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name1, name2 = _sort(name1, name2)
         self.hbonds[(name1, name2)] = \
                             AmberHbondParameters(self.atom_types[name1],
                                                  self.atom_types[name2],
                                                  l[2], l[3])
示例#10
0
 def _readAngleParameters(self, file):
     format = FortranFormat('A2,1X,A2,1X,A2,2F10.2')
     while True:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name3 = _normalizeName(l[2])
         name1, name3 = _sort(name1, name3)
         self.bond_angles[(name1, name2, name3)] = \
                AmberBondAngleParameters(self.atom_types[name1],
                                         self.atom_types[name2],
                                         self.atom_types[name3],
                                         l[3], l[4])
 def _readAngleParameters(self, file):
     format = FortranFormat('A2,1X,A2,1X,A2,2F10.2')
     while 1:
         l = FortranLine(file.readline()[:-1], format)
         if l.isBlank(): break
         name1 = _normalizeName(l[0])
         name2 = _normalizeName(l[1])
         name3 = _normalizeName(l[2])
         name1, name3 = _sort(name1, name3)
         self.bond_angles[(name1, name2, name3)] = \
                AmberBondAngleParameters(self.atom_types[name1],
                                         self.atom_types[name2],
                                         self.atom_types[name3],
                                         l[3], l[4])
示例#12
0
    def __init__(self, file, modifications=[]):
        if isinstance(file, basestring):
            file = TextFile(file)
        title = file.readline()[:-1]

        self.atom_types = DictWithDefault(None)
        self._readAtomTypes(file)

        format = FortranFormat('20(A2,2X)')
        done = False
        while not done:
            l = FortranLine(file.readline()[:-1], format)
            for entry in l:
                name = _normalizeName(entry)
                if len(name) == 0:
                    done = True
                    break
                try: # ignore errors for now
                    self.atom_types[name].hydrophylic = True
                except: pass

        self.bonds = {}
        self._readBondParameters(file)

        self.bond_angles = {}
        self._readAngleParameters(file)

        self.dihedrals = {}
        self.dihedrals_2 = {}
        self._readDihedralParameters(file)

        self.impropers = {}
        self.impropers_1 = {}
        self.impropers_2 = {}
        self._readImproperParameters(file)

        self.hbonds = {}
        self._readHbondParameters(file)

        self.lj_equivalent = {}
        format = FortranFormat('20(A2,2X)')
        while True:
            l = FortranLine(file.readline()[:-1], format)
            if l.isBlank(): break
            name1 = _normalizeName(l[0])
            for s in l[1:]:
                name2 = _normalizeName(s)
                self.lj_equivalent[name2] = name1

        self.ljpar_sets = {}
        while True:
            l = FortranLine(file.readline()[:-1], 'A4,6X,A2')
            if l[0] == 'END ': break
            set_name = _normalizeName(l[0])
            ljpar_set = AmberLJParameterSet(set_name, l[1])
            self.ljpar_sets[set_name] = ljpar_set
            self._readLJParameters(file, ljpar_set)

        file.close()

        for mod, ljname in modifications:
            if isinstance(mod, basestring):
                file = TextFile(mod)
            else:
                file = mod
            title = file.readline()[:-1]
            blank = file.readline()[:-1]
            while True:
                keyword = file.readline()
                if not keyword: break
                keyword = keyword.strip()[:4]
                if keyword == 'MASS':
                    self._readAtomTypes(file)
                elif keyword == 'BOND':
                    self._readBondParameters(file)
                elif keyword == 'ANGL':
                    self._readAngleParameters(file)
                elif keyword == 'DIHE':
                    self._readDihedralParameters(file)
                elif keyword == 'IMPR':
                    self._readImproperParameters(file)
                elif keyword == 'HBON':
                    self._readHbondParameters(file)
                elif keyword == 'NONB':
                    self._readLJParameters(file, self.ljpar_sets[ljname])
    def __init__(self, file, modifications=[]):
        if isinstance(file, str):
            file = TextFile(file)
        title = file.readline()[:-1]

        self.atom_types = DictWithDefault(None)
        self._readAtomTypes(file)

        format = FortranFormat('20(A2,2X)')
        done = 0
        while not done:
            l = FortranLine(file.readline()[:-1], format)
            for entry in l:
                name = _normalizeName(entry)
                if len(name) == 0:
                    done = 1
                    break
                try:  # ignore errors for now
                    self.atom_types[name].hydrophylic = 1
                except:
                    pass

        self.bonds = {}
        self._readBondParameters(file)

        self.bond_angles = {}
        self._readAngleParameters(file)

        self.dihedrals = {}
        self.dihedrals_2 = {}
        self._readDihedralParameters(file)

        self.impropers = {}
        self.impropers_1 = {}
        self.impropers_2 = {}
        self._readImproperParameters(file)

        self.hbonds = {}
        self._readHbondParameters(file)

        self.lj_equivalent = {}
        format = FortranFormat('20(A2,2X)')
        while 1:
            l = FortranLine(file.readline()[:-1], format)
            if l.isBlank(): break
            name1 = _normalizeName(l[0])
            for s in l[1:]:
                name2 = _normalizeName(s)
                self.lj_equivalent[name2] = name1

        self.ljpar_sets = {}
        while 1:
            l = FortranLine(file.readline()[:-1], 'A4,6X,A2')
            if l[0] == 'END ': break
            set_name = _normalizeName(l[0])
            ljpar_set = AmberLJParameterSet(set_name, l[1])
            self.ljpar_sets[set_name] = ljpar_set
            self._readLJParameters(file, ljpar_set)

        file.close()

        for mod, ljname in modifications:
            if isinstance(mod, str):
                file = TextFile(mod)
            else:
                file = mod
            title = file.readline()[:-1]
            blank = file.readline()[:-1]
            while 1:
                keyword = file.readline()
                if not keyword: break
                keyword = string.strip(keyword)[:4]
                if keyword == 'MASS':
                    self._readAtomTypes(file)
                elif keyword == 'BOND':
                    self._readBondParameters(file)
                elif keyword == 'ANGL':
                    self._readAngleParameters(file)
                elif keyword == 'DIHE':
                    self._readDihedralParameters(file)
                elif keyword == 'IMPR':
                    self._readImproperParameters(file)
                elif keyword == 'HBON':
                    self._readHbondParameters(file)
                elif keyword == 'NONB':
                    self._readLJParameters(file, self.ljpar_sets[ljname])