コード例 #1
0
def categorizeVariables(variable_names):
    categories = DictWithDefault([])
    for name in variable_names:
        words = (name.split('_'))
        try:
            c = _category[words[-1]]
        except KeyError:
            c = ''
        if c:
            categories[c].append(name)
    for list in categories.values():
        list.sort()
    if categories.has_key('energy'):
        list = categories['energy']
        for variable in ['kinetic_energy', 'potential_energy']:
            if variable in list:
                list.remove(variable)
                list = [variable] + list
        categories['energy'] = list
    return categories
コード例 #2
0
def categorizeVariables(variable_names):
    categories = DictWithDefault([])
    for name in variable_names:
        words = string.split(name, '_')
        try:
            c = _category[words[-1]]
        except KeyError:
            c = ''
        if c:
            categories[c].append(name)
    for list in categories.values():
        list.sort()
    if categories.has_key('energy'):
        list = categories['energy']
        for variable in ['kinetic_energy', 'potential_energy']:
            if variable in list:
                list.remove(variable)
                list = [variable] + list
        categories['energy'] = list
    return categories
コード例 #3
0
ファイル: ChemicalObjects.py プロジェクト: fxia22/ASM_xf
    def findHydrogenPositions(self):
        """Find reasonable positions for hydrogen atoms that have no
        position assigned.

        This method uses a heuristic approach based on standard geometry
        data. It was developed for proteins and DNA and may not give
        good results for other molecules. It raises an exception
        if presented with a topology it cannot handle."""
	self.setBondAttributes()
	try:
	    unknown = DictWithDefault([])
	    for a in self.atoms:
		if a.position() is None:
		    if a.symbol != 'H':
			raise ValueError, 'position of ' + a.fullName() + \
			      ' is undefined'
		    bonded = a.bondedTo()[0]
		    unknown[bonded].append(a)
	    for a, list in unknown.items():
		bonded = a.bondedTo()
		n = len(bonded)
		known = []
		for b in bonded:
		    if b.position() is not None:
			known.append(b)
		nb = len(list)
		if a.symbol == 'C':
		    if n == 4:
			if nb == 1:
			    self._C4oneH(a, known, list)
			elif nb == 2:
			    self._C4twoH(a, known, list)
			elif nb == 3:
			    self._C4threeH(a, known, list)
		    elif n == 3:
                        if nb == 1:
                            self._C3oneH(a, known, list)
                        else:
                            self._C3twoH(a, known, list)
		    else:
			print a
			raise ValueError, "Can't handle C with "+`n`+" bonds"
		elif a.symbol == 'N':
		    if n == 4:
			if nb == 3:
			    self._N4threeH(a, known, list)
                        elif nb == 2:
			    self._N4twoH(a, known, list)
		    elif n == 3:
			if nb == 1:
			    self._N3oneH(a, known, list)
			elif nb == 2:
			    self._N3twoH(a, known, list)
		    else:
			print a
			raise ValueError, "Can't handle N with "+`n`+" bonds"
		elif a.symbol == 'O' and n == 2:
		    self._O2(a, known, list)
		elif a.symbol == 'S' and n == 2:
		    self._S2(a, known, list)
		else:
		    print a
		    raise ValueError, "Can't handle this yet: " + \
			  a.symbol + ' with ' + `n` + ' bonds (' + \
			  a.fullName() + ').'
	finally:
	    self.clearBondAttributes()
コード例 #4
0
    def findHydrogenPositions(self):
        """Find reasonable positions for hydrogen atoms that have no
        position assigned.

        This method uses a heuristic approach based on standard geometry
        data. It was developed for proteins and DNA and may not give
        good results for other molecules. It raises an exception
        if presented with a topology it cannot handle."""
        self.setBondAttributes()
        try:
            unknown = DictWithDefault([])
            for a in self.atoms:
                if a.position() is None:
                    if a.symbol != 'H':
                        raise ValueError('position of ' + a.fullName() + \
                                          ' is undefined')
                    bonded = a.bondedTo()[0]
                    unknown[bonded].append(a)
            for a, list in unknown.items():
                bonded = a.bondedTo()
                n = len(bonded)
                known = []
                for b in bonded:
                    if b.position() is not None:
                        known.append(b)
                nb = len(list)
                if a.symbol == 'C':
                    if n == 4:
                        if nb == 1:
                            self._C4oneH(a, known, list)
                        elif nb == 2:
                            self._C4twoH(a, known, list)
                        elif nb == 3:
                            self._C4threeH(a, known, list)
                    elif n == 3:
                        if nb == 1:
                            self._C3oneH(a, known, list)
                        else:
                            self._C3twoH(a, known, list)
                    elif n == 2:
                        self._C2oneH(a, known, list)
                    else:
                        print a
                        raise ValueError("Can't handle C with " + ` n ` +
                                         " bonds")
                elif a.symbol == 'N':
                    if n == 4:
                        if nb == 3:
                            self._N4threeH(a, known, list)
                        elif nb == 2:
                            self._N4twoH(a, known, list)
                        elif nb == 1:
                            self._N4oneH(a, known, list)
                    elif n == 3:
                        if nb == 1:
                            self._N3oneH(a, known, list)
                        elif nb == 2:
                            self._N3twoH(a, known, list)
                    elif n == 2:
                        self._N2oneH(a, known, list)
                    else:
                        print a
                        raise ValueError("Can't handle N with " + ` n ` +
                                         " bonds")
                elif a.symbol == 'O' and n == 2:
                    self._O2(a, known, list)
                elif a.symbol == 'S' and n == 2:
                    self._S2(a, known, list)
                else:
                    print a
                    raise ValueError("Can't handle this yet: " + a.symbol +
                                     ' with ' + ` n ` + ' bonds (' +
                                     a.fullName() + ').')
        finally:
            self.clearBondAttributes()
コード例 #5
0
    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])