📄 pdbreader.java
字号:
if (isProteinStructure) { if (oBP.getAtomCount() > 0) { // save the model oSet.addAtomContainer(oBP); oModel.setMoleculeSet(oSet); oSeq.addChemModel(oModel); // setup a new one oBP = new PDBPolymer(); oModel = oFile.getBuilder().newChemModel(); oSet = oFile.getBuilder().newMoleculeSet(); } } else { if (molecularStructure.getAtomCount() > 0) {// save the model oSet.addAtomContainer(molecularStructure); oModel.setMoleculeSet(oSet); oSeq.addChemModel(oModel); // setup a new one molecularStructure = oFile.getBuilder().newMolecule(); oModel = oFile.getBuilder().newChemModel(); oSet = oFile.getBuilder().newMoleculeSet(); } } } else if ("REMARK".equalsIgnoreCase(cCol)) { Object comment = oFile.getProperty(CDKConstants.COMMENT); if (comment == null) { comment = ""; } if (lineLength >12) { comment = comment.toString() + cRead.substring(11).trim() + "\n"; oFile.setProperty(CDKConstants.COMMENT, comment); } else { logger.warn("REMARK line found without any comment!"); } } else if ("COMPND".equalsIgnoreCase(cCol)) { String title = cRead.substring(10).trim(); oFile.setProperty(CDKConstants.TITLE, title); } /************************************************************* * Read connectivity information from CONECT records. * Only covalent bonds are dealt with. Perhaps salt bridges * should be dealt with in the same way..? */ else if (readConnect.isSet() && "CONECT".equalsIgnoreCase(cCol)) { cRead.trim(); if (cRead.length() < 16) { logger.debug("Skipping unexpected empty CONECT line! : ", cRead); } else { String bondAtom = cRead.substring(7, 11).trim(); int bondAtomNo = Integer.parseInt(bondAtom); String bondedAtom = cRead.substring(12, 16).trim(); int bondedAtomNo = -1; try {bondedAtomNo = Integer.parseInt(bondedAtom);} catch(Exception e) {bondedAtomNo = -1;} if(bondedAtomNo != -1) { addBond(oBP, bondAtomNo, bondedAtomNo); logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo); } if(cRead.length() > 17) { bondedAtom = cRead.substring(17, 21); bondedAtom = bondedAtom.trim(); try {bondedAtomNo = Integer.parseInt(bondedAtom);} catch(Exception e) {bondedAtomNo = -1;} if(bondedAtomNo != -1) { addBond(oBP, bondAtomNo, bondedAtomNo); logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo); } } if(cRead.length() > 22) { bondedAtom = cRead.substring(22, 26); bondedAtom = bondedAtom.trim(); try {bondedAtomNo = Integer.parseInt(bondedAtom);} catch(Exception e) {bondedAtomNo = -1;} if(bondedAtomNo != -1) { addBond(oBP, bondAtomNo, bondedAtomNo); logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo); } } if(cRead.length() > 27) { bondedAtom = cRead.substring(27, 31); bondedAtom = bondedAtom.trim(); try {bondedAtomNo = Integer.parseInt(bondedAtom);} catch(Exception e) {bondedAtomNo = -1;} if(bondedAtomNo != -1) { addBond(oBP, bondAtomNo, bondedAtomNo); logger.warn("Bonded " + bondAtomNo + " with " + bondedAtomNo); } } } } /*************************************************************/ else if ("HELIX ".equalsIgnoreCase(cCol)) {// HELIX 1 H1A CYS A 11 LYS A 18 1 RESIDUE 18 HAS POSITIVE PHI 1D66 72// 1 2 3 4 5 6 7// 01234567890123456789012345678901234567890123456789012345678901234567890123456789 PDBStructure structure = new PDBStructure(); structure.setStructureType(PDBStructure.HELIX); structure.setStartChainID(cRead.charAt(19)); structure.setStartSequenceNumber(Integer.parseInt(cRead.substring(21, 25).trim())); structure.setStartInsertionCode(cRead.charAt(25)); structure.setEndChainID(cRead.charAt(31)); structure.setEndSequenceNumber(Integer.parseInt(cRead.substring(33, 37).trim())); structure.setEndInsertionCode(cRead.charAt(37)); oBP.addStructure(structure); } else if ("SHEET ".equalsIgnoreCase(cCol)) { PDBStructure structure = new PDBStructure(); structure.setStructureType(PDBStructure.SHEET); structure.setStartChainID(cRead.charAt(21)); structure.setStartSequenceNumber(Integer.parseInt(cRead.substring(22, 26).trim())); structure.setStartInsertionCode(cRead.charAt(26)); structure.setEndChainID(cRead.charAt(32)); structure.setEndSequenceNumber(Integer.parseInt(cRead.substring(33, 37).trim())); structure.setEndInsertionCode(cRead.charAt(37)); oBP.addStructure(structure); } else if ("TURN ".equalsIgnoreCase(cCol)) { PDBStructure structure = new PDBStructure(); structure.setStructureType(PDBStructure.TURN); structure.setStartChainID(cRead.charAt(19)); structure.setStartSequenceNumber(Integer.parseInt(cRead.substring(20, 24).trim())); structure.setStartInsertionCode(cRead.charAt(24)); structure.setEndChainID(cRead.charAt(30)); structure.setEndSequenceNumber(Integer.parseInt(cRead.substring(31, 35).trim())); structure.setEndInsertionCode(cRead.charAt(35)); oBP.addStructure(structure); } // ignore all other commands } } while (_oInput.ready() && (cRead != null)); } catch (Exception e) { logger.error("Found a problem at line:\n"); logger.error(cRead); logger.error("01234567890123456789012345678901234567890123456789012345678901234567890123456789"); logger.error(" 1 2 3 4 5 6 7 "); logger.error(" error: " + e.getMessage()); logger.debug(e); } // try to close the Input try { _oInput.close(); } catch (Exception e) { logger.debug(e); } // Set all the dependencies oModel.setMoleculeSet(oSet); oSeq.addChemModel(oModel); oFile.addChemSequence(oSeq); return oFile; } private void addBond(PDBPolymer obp, int bondAtomNo, int bondedAtomNo) { IAtom firstAtom = (PDBAtom)atomNumberMap.get(new Integer(bondAtomNo)); IAtom secondAtom = (PDBAtom)atomNumberMap.get(new Integer(bondedAtomNo)); if (firstAtom == null) { logger.error("Could not find bond start atom in map with serial id: ", bondAtomNo); } if (secondAtom == null) { logger.error("Could not find bond target atom in map with serial id: ", bondAtomNo); } obp.addBond(firstAtom.getBuilder().newBond(firstAtom, secondAtom, 1)); } private boolean createBondsWithRebondTool(IBioPolymer pol){ RebondTool tool = new RebondTool(2.0, 0.5, 0.5); try {// configure atoms AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", pol.getBuilder()); java.util.Iterator atoms = pol.atoms(); while (atoms.hasNext()) { IAtom atom = (IAtom)atoms.next(); try { IAtomType[] types = factory.getAtomTypes(atom.getSymbol()); if (types.length > 0) { // just pick the first one AtomTypeManipulator.configure(atom, types[0]); } else { logger.warn("Could not configure atom with symbol: "+ atom.getSymbol()); } } catch (Exception e) { logger.warn("Could not configure atom (but don't care): " + e.getMessage()); logger.debug(e); } } tool.rebond(pol); } catch (Exception e) { logger.error("Could not rebond the polymer: " + e.getMessage()); logger.debug(e); } return true; } /** * Creates an <code>Atom</code> and sets properties to their values from * the ATOM record. If the line is shorter than 80 characters, the information * past 59 characters is treated as optional. If the line is shorter than 59 * characters, a <code>RuntimeException</code> is thrown. * * @param cLine the PDB ATOM record. * @return the <code>Atom</code> created from the record. * @throws RuntimeException if the line is too short (less than 59 characters). */ private PDBAtom readAtom(String cLine, int lineLength) { // a line looks like: // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 // ATOM 1 O5* C A 1 20.662 36.632 23.475 1.00 10.00 114D 45 // ATOM 1186 1H ALA 1 10.105 5.945 -6.630 1.00 0.00 1ALE1288 if (lineLength < 59) { throw new RuntimeException("PDBReader error during readAtom(): line too short"); } String elementSymbol = cLine.substring(12, 14).trim(); if (elementSymbol.length() == 2) { // ensure that the second char is lower case elementSymbol = elementSymbol.charAt(0) + elementSymbol.substring(1).toLowerCase(); } String rawAtomName = cLine.substring(12, 16).trim(); String resName = cLine.substring(17, 20).trim(); try { IAtomType type = pdbFactory.getAtomType(resName+"."+rawAtomName); elementSymbol = type.getSymbol(); } catch (NoSuchAtomTypeException e) { logger.error("Did not recognize PDB atom type: " + resName+"."+rawAtomName); } PDBAtom oAtom = new PDBAtom(elementSymbol, new Point3d(Double.parseDouble(cLine.substring(30, 38)), Double.parseDouble(cLine.substring(38, 46)), Double.parseDouble(cLine.substring(46, 54)) ) ); oAtom.setRecord(cLine); oAtom.setSerial(Integer.parseInt(cLine.substring(6, 11).trim())); oAtom.setName(rawAtomName.trim()); oAtom.setAltLoc(cLine.substring(16, 17).trim()); oAtom.setResName(resName); oAtom.setChainID(cLine.substring(21, 22).trim()); oAtom.setResSeq(cLine.substring(22, 26).trim()); oAtom.setICode(cLine.substring(26, 27).trim()); oAtom.setAtomTypeName(oAtom.getResName()+"."+rawAtomName); if (lineLength >= 59) { String frag = cLine.substring(54, 60).trim(); if (frag.length() > 0) { oAtom.setOccupancy(Double.parseDouble(frag)); } } if (lineLength >= 65) { String frag = cLine.substring(60, 66).trim(); if (frag.length() > 0) { oAtom.setTempFactor(Double.parseDouble(frag)); } } if (lineLength >= 75) { oAtom.setSegID(cLine.substring(72, 76).trim()); }// if (lineLength >= 78) {// oAtom.setSymbol((new String(cLine.substring(76, 78))).trim());// } if (lineLength >= 79) { String frag = cLine.substring(78, 80).trim(); if (frag.length() > 0) { oAtom.setCharge(Double.parseDouble(frag)); } } /************************************************************************************* * It sets a flag in the property content of an atom, * which is used when bonds are created to check if the atom is an OXT-record => needs * special treatment. */ String oxt = cLine.substring(13, 16).trim(); if(oxt.equals("OXT")) { oAtom.setOxt(true); } else { oAtom.setOxt(false); } /*************************************************************************************/ return oAtom; } public void close() throws IOException { _oInput.close(); } private void initIOSettings() { useRebondTool = new BooleanIOSetting("UseRebondTool", IOSetting.LOW, "Should the PDBReader deduce bonding patterns?", "false"); readConnect = new BooleanIOSetting("ReadConnectSection", IOSetting.LOW, "Should the CONECT be read?", "true"); } public void customizeJob() { fireIOSettingQuestion(useRebondTool); fireIOSettingQuestion(readConnect); } public IOSetting[] getIOSettings() { IOSetting[] settings = new IOSetting[2]; settings[0] = useRebondTool; settings[1] = readConnect; return settings; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -