📄 pmpreader.java
字号:
// bondids.put(new Integer(id), new Integer(molecule.getAtomCount()));// molecule.addBond((IBond)chemObject); } else { logger.error("chemObject is not initialized or of bad class type"); } // logger.debug(molecule.toString()); } line = readLine(); } if (line.startsWith("%%Model End")) { // during the Model Start, all bonds are cached as PMP files might // define bonds *before* the involved atoms :( // the next lines dump the cache into the atom container// bondids.put(new Integer(id), new Integer(molecule.getAtomCount()));// molecule.addBond((IBond)chemObject); int bondsFound = bondids.size(); logger.debug("Found #bonds: ", bondsFound); logger.debug("#atom ones: ", bondAtomOnes.size()); logger.debug("#atom twos: ", bondAtomTwos.size()); logger.debug("#orders: ", bondOrders.size()); Iterator bonds = bondids.keySet().iterator(); while (bonds.hasNext()) { Integer index = (Integer)bonds.next(); double order = (bondOrders.get(index) != null ? ((Double)bondOrders.get(index)).doubleValue() : 1.0); logger.debug("index: ", index); logger.debug("ones: ", bondAtomOnes.get(index)); IAtom atom1 = modelStructure.getAtom( ((Integer)atomids.get( (Integer)bondAtomOnes.get(index) )).intValue() ); IAtom atom2 = modelStructure.getAtom( ((Integer)atomids.get( (Integer)bondAtomTwos.get(index) )).intValue() ); IBond bond = modelStructure.getBuilder().newBond(atom1, atom2, order); modelStructure.addBond(bond); } } } else if (line.startsWith("%%Traj Start")) { chemSequence = chemFile.getBuilder().newChemSequence(); double energyFragment = 0.0; double energyTotal = 0.0; int Z = 1; while (input.ready() && line != null && !(line.startsWith("%%Traj End"))) { if (line.startsWith("%%Start Frame")) { chemModel = chemFile.getBuilder().newChemModel(); crystal = chemFile.getBuilder().newCrystal(); while (input.ready() && line != null && !(line.startsWith("%%End Frame"))) { // process frame data if (line.startsWith("%%Atom Coords")) { // calculate Z: as it is not explicitely given, try to derive it from the // energy per fragment and the total energy if (energyFragment != 0.0 && energyTotal != 0.0) { Z = (int)Math.round(energyTotal/energyFragment); logger.debug("Z derived from energies: ", Z); } // add atomC as atoms to crystal int expatoms = modelStructure.getAtomCount(); for (int molCount = 1; molCount<=Z; molCount++) { IAtomContainer clone = modelStructure.getBuilder().newAtomContainer(); for (int i=0; i < expatoms; i++) { line = readLine(); IAtom a = clone.getBuilder().newAtom(); StringTokenizer st = new StringTokenizer(line, " "); a.setPoint3d( new Point3d( Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()) ) ); a.setCovalentRadius(0.6); IAtom modelAtom = modelStructure.getAtom(((Integer)atomids.get(atomGivenIds.get(new Integer(i+1)))).intValue()); a.setSymbol(modelAtom.getSymbol()); clone.addAtom(a); } rebonder.rebond(clone); crystal.add(clone); } } else if (line.startsWith("%%E/Frag")) { line = readLine().trim(); energyFragment = Double.parseDouble(line); } else if (line.startsWith("%%Tot E")) { line = readLine().trim(); energyTotal = Double.parseDouble(line); } else if (line.startsWith("%%Lat Vects")) { StringTokenizer st; line = readLine(); st = new StringTokenizer(line, " "); crystal.setA(new Vector3d( Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()) )); line = readLine(); st = new StringTokenizer(line, " "); crystal.setB(new Vector3d( Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()) )); line = readLine(); st = new StringTokenizer(line, " "); crystal.setC(new Vector3d( Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()) )); } else if (line.startsWith("%%Space Group")) { line = readLine().trim(); /* standardize space group name. See Crystal.setSpaceGroup() */ if ("P 21 21 21 (1)".equals(line)) { crystal.setSpaceGroup("P 2_1 2_1 2_1"); } else { crystal.setSpaceGroup("P1"); } } else { } line = readLine(); } chemModel.setCrystal(crystal); chemSequence.addChemModel(chemModel); } line = readLine(); } chemFile.addChemSequence(chemSequence); } else { // disregard line } // read next line line = readLine(); } } catch (IOException e) { logger.error("An IOException happened: ", e.getMessage()); logger.debug(e); chemFile = null; } catch (CDKException e) { logger.error("An CDKException happened: ", e.getMessage()); logger.debug(e); chemFile = null; } return chemFile; } private void processModelCommand(String object, String command, String format, String field) { logger.debug(object + "->" + command + " (" + format + "): " + field); if ("Model".equals(object)) { logger.warn("Unkown PMP Model command: " + command); } else if ("Atom".equals(object)) { if ("ACL".equals(command)) { Matcher atomTypeMatcher = atomTypePattern.matcher(field); if (atomTypeMatcher.matches()) { int atomicnum = Integer.parseInt(atomTypeMatcher.group(1)); String type = atomTypeMatcher.group(2); ((IAtom)chemObject).setAtomicNumber(atomicnum); ((IAtom)chemObject).setSymbol(type); } else { logger.error("Incorrectly formated field value: " + field + "."); } } else if ("Charge".equals(command)) { try { double charge = Double.parseDouble(field); ((IAtom)chemObject).setCharge(charge); } catch (NumberFormatException e) { logger.error("Incorrectly formated float field: " + field + "."); } } else if ("CMAPPINGS".equals(command)) { } else if ("FFType".equals(command)) { } else if ("Id".equals(command)) { // ok, should take this into account too chemObject.setProperty(PMP_ID, field); } else if ("Mass".equals(command)) { } else if ("XYZ".equals(command)) { } else if ("ZOrder".equals(command)) { // ok, should take this into account too chemObject.setProperty(PMP_ZORDER, field); } else { logger.warn("Unkown PMP Atom command: " + command); } } else if ("Bond".equals(object)) { if ("Atom1".equals(command)) { int atomid = Integer.parseInt(field); // this assumes that the atoms involved in this bond are // already added, which seems the case in the PMP files bondAtomOnes.put(new Integer(bondCounter), new Integer(atomid));// IAtom a = molecule.getAtom(realatomid);// ((IBond)chemObject).setAtomAt(a, 0); } else if ("Atom2".equals(command)) { int atomid = Integer.parseInt(field); // this assumes that the atoms involved in this bond are // already added, which seems the case in the PMP files logger.debug("atomids: " + atomids); logger.debug("atomid: " + atomid); bondAtomTwos.put(new Integer(bondCounter), new Integer(atomid));// IAtom a = molecule.getAtom(realatomid);// ((IBond)chemObject).setAtomAt(a, 1); } else if ("Order".equals(command)) { double order = Double.parseDouble(field); bondOrders.put(new Integer(bondCounter), new Double(order));// ((IBond)chemObject).setOrder(order); } else if ("Id".equals(command)) { int bondid = Integer.parseInt(field); bondids.put(new Integer(bondCounter), new Integer(bondid)); } else if ("Label".equals(command)) { } else if ("3DGridOrigin".equals(command)) { } else if ("3DGridMatrix".equals(command)) { } else if ("3DGridDivision".equals(command)) { } else { logger.warn("Unkown PMP Bond command: " + command); } } else { logger.warn("Unkown PMP object: " + object); } } private void constructObject(IChemObjectBuilder builder, String object) { if ("Atom".equals(object)) { chemObject = builder.newAtom("C"); } else if ("Bond".equals(object)) { bondCounter++; chemObject = builder.newBond(); } else if ("Model".equals(object)) { modelStructure = builder.newAtomContainer(); } else { logger.error("Cannot construct PMP object type: " + object); } }; public void close() throws IOException { input.close(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -