def save(self, filename): # WIP self.filename = filename exception = None open_file = None try: if not self.filename: raise IOError("no filename specified for saving") open_file = open(self.filename, 'w') dataExtra = self.extractInitData() GRO_parse.write_extraData_to_GRO(open_file, dataExtra[0]) GRO_parse.write_extraData_to_GRO(open_file, [str(self.rowCount())]) for row in self.GRO_rows: residNum = row.residNum residName = row.residName # (residNum, residName, atomName, atomNum, X,Y,Z ) = range(7) atomName = row.atomName atomNum = row.atomNum x = row.X y = row.Y z = row.Z line = [residNum, residName, atomName, atomNum, x, y, z] # print('line is ',line) GRO_parse.write_SingleLine_to_GRO(open_file, line) GRO_parse.write_vectorBox_to_GRO(open_file, dataExtra[2]) self.dirty = False except IOError as e: exception = e finally: if open_file is not None: open_file.close() if exception is not None: raise exception
def load(self): exception = None fh = None try: if not self.filename: raise IOError("no filename specified for loading") self.mol = GRO_parse.groParse(self.filename) for row in self.mol: ATOM = row[0] serial = row[1] name = row[2] resName = row[3] ChainID = row[4] resNum = row[5] X = row[6] Y = row[7] Z = row[8] occupancy = row[9] charge = row[10] element = row[11] GROrow = GRO_rowInfo(ATOM, serial, name, resName, ChainID, resNum, X, Y, Z, occupancy, charge, element) self.PDB_ROWS[id(GROrow)] = GROrow self.dirty = False except IOError as e: exception = e
def load(self, fname): # This parts need modification self.filename = fname exception = None fh = None try: if self.filename != '': if not self.filename: raise IOError("no filename specified for loading") self.GRO_rows = [] self.molTotal = GRO_parse.groParse(self.filename) self.mol = self.molTotal[2:-1] # print('self.mol is ',self.mol) self.flag_color = True self.val = int(self.mol[2][0]) for row in self.mol: residNum = row[0] if self.val != int(residNum): if self.flag_color == True: self.flag_color = False # self.val = int(resNum) residNum_color = QColor(Qt.green) elif self.flag_color == False: self.flag_color = True # self.val = int(GRO_row.resNum) residNum_color = QColor(Qt.yellow) self.val = int(residNum) elif self.flag_color == True and self.val == int(residNum): residNum_color = QColor(Qt.yellow) elif self.flag_color == False and self.val == int(residNum): residNum_color = QColor(Qt.green) residName = row[1] if residName in RESID_COLORS_RGB: Col = RESID_COLORS_RGB[residName] residName_color = QColor(Col[0], Col[1], Col[2]) else: Col = RESID_COLORS_RGB['other'] residName_color = QColor(Col[0], Col[1], Col[2]) atomName = row[2] atomNum = row[3] X = row[4] Y = row[5] Z = row[6] GROrow = GRO_rowInfo(residNum, residNum_color, residName, residName_color, atomName, atomNum, X, Y, Z) self.GRO_rows.append(GROrow) self.dirty = False # self.extractInitData() #For test Purpose except IOError as e: exception = e finally: if fh is not None: fh.close() if exception is not None: raise exception