Mercurial > repos > guerler > springsuite
comparison spring_package/Molecule.py @ 39:172398348efd draft
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
| author | guerler |
|---|---|
| date | Fri, 22 Jan 2021 15:50:27 +0000 |
| parents | 0be0af9e695d |
| children |
comparison
equal
deleted
inserted
replaced
| 38:80a4b98121b6 | 39:172398348efd |
|---|---|
| 84 matId = self.toInt(nextLine[20:23]) | 84 matId = self.toInt(nextLine[20:23]) |
| 85 matLine = nextLine[23:].split() | 85 matLine = nextLine[23:].split() |
| 86 matLine = list(map(lambda x: self.toFloat(x), matLine)) | 86 matLine = list(map(lambda x: self.toFloat(x), matLine)) |
| 87 return matId, matLine | 87 return matId, matLine |
| 88 | 88 |
| 89 def createUnit(self, biomolNumber=1): | 89 def createUnit(self, biomolNumber=0): |
| 90 molecule = Molecule() | 90 if biomolNumber == 0: |
| 91 chainCount = 0 | 91 return self |
| 92 for matrixDict in self.biomol[biomolNumber]: | 92 else: |
| 93 for chain in matrixDict["chains"]: | 93 molecule = Molecule() |
| 94 if chain in self.calpha: | 94 chainCount = dict() |
| 95 chainCopy = dict() | 95 for matrixDict in self.biomol[biomolNumber]: |
| 96 for residue in self.calpha[chain]: | 96 for chain in matrixDict["chains"]: |
| 97 chainCopy[residue] = self.calpha[chain][residue].copy() | 97 if chain in self.calpha: |
| 98 for atomNumber in chainCopy: | 98 chainCopy = dict() |
| 99 atom = chainCopy[atomNumber] | 99 for residue in self.calpha[chain]: |
| 100 rotmat = matrixDict["matrix"] | 100 chainCopy[residue] = self.calpha[chain][residue].copy() |
| 101 self.applyMatrix(atom, rotmat) | 101 for atomNumber in chainCopy: |
| 102 if chain in molecule.calpha: | 102 atom = chainCopy[atomNumber] |
| 103 chainName = "%s%d" % (chain, chainCount) | 103 rotmat = matrixDict["matrix"] |
| 104 else: | 104 self.applyMatrix(atom, rotmat) |
| 105 chainName = chain | 105 if chain in chainCount: |
| 106 molecule.calpha[chainName] = chainCopy | 106 chainCount = chainCount[chain] |
| 107 chainCount = chainCount + 1 | 107 chainName = "%s_%d" % (chain, chainCount) |
| 108 return molecule | 108 chainCount[chain] = chainCount + 1 |
| 109 else: | |
| 110 chainName = chain | |
| 111 chainCount[chain] = 0 | |
| 112 molecule.calpha[chainName] = chainCopy | |
| 113 return molecule | |
| 109 | 114 |
| 110 def getSequence(self, chainName): | 115 def getSequence(self, chainName): |
| 111 seq = "" | 116 seq = "" |
| 112 if chainName not in self.calpha: | 117 if chainName not in self.calpha: |
| 113 raise Exception("Chain identifier not found [%s]" % chainName) | 118 raise Exception("Chain identifier not found [%s]" % chainName) |
| 143 code = dict(GLY="G", ALA="A", VAL="V", LEU="L", ILE="I", MET="M", PHE="F", PRO="P", TYR="Y", TRP="W", | 148 code = dict(GLY="G", ALA="A", VAL="V", LEU="L", ILE="I", MET="M", PHE="F", PRO="P", TYR="Y", TRP="W", |
| 144 LYS="K", SER="S", CYS="C", ASN="N", GLN="Q", HIS="H", THR="T", GLU="E", ASP="D", ARG="R") | 149 LYS="K", SER="S", CYS="C", ASN="N", GLN="Q", HIS="H", THR="T", GLU="E", ASP="D", ARG="R") |
| 145 return code[seq] if seq in code else "X" | 150 return code[seq] if seq in code else "X" |
| 146 | 151 |
| 147 def saveChain(self, chainName, outputName): | 152 def saveChain(self, chainName, outputName): |
| 148 print("Writing PDB file to %s." % outputName) | |
| 149 f = open(outputName, "w") | 153 f = open(outputName, "w") |
| 150 for residueNumber in sorted(self.calpha[chainName].keys()): | 154 for residueNumber in sorted(self.calpha[chainName].keys()): |
| 151 ca = self.calpha[chainName][residueNumber] | 155 ca = self.calpha[chainName][residueNumber] |
| 152 if ca["residue"] is not None: | 156 if ca["residue"] is not None: |
| 153 f.write(self.atomString(ca)) | 157 f.write(self.atomString(ca)) |
| 154 f.close() | 158 f.close() |
| 155 | 159 |
| 156 def save(self, outputName, append=False, chainName=None): | 160 def save(self, outputName, append=False, chainName=None, payload=None): |
| 157 print("Writing atoms to PDB file to %s." % outputName) | |
| 158 fileFlag = "+a" if append else "w" | 161 fileFlag = "+a" if append else "w" |
| 159 f = open(outputName, fileFlag) | 162 f = open(outputName, fileFlag) |
| 163 if payload: | |
| 164 f.write("%s\n" % payload) | |
| 160 for atom in self.atoms: | 165 for atom in self.atoms: |
| 161 atom["chainName"] = chainName if chainName else atom["chainName"] | 166 atom["chainName"] = chainName if chainName else atom["chainName"] |
| 162 f.write(self.atomString(atom)) | 167 f.write(self.atomString(atom)) |
| 163 f.write("TER\n") | 168 f.write("TER\n") |
| 164 f.close() | 169 f.close() |
