List of usage examples for java.lang Character equals
public boolean equals(Object obj)
From source file:ffx.potential.parsers.BiojavaFilter.java
/** * <p>/*w w w .ja va2 s . c o m*/ * writeFile</p> * * @param saveFile a {@link java.io.File} object. * @param append a {@link java.lang.StringBuilder} object. * @param printLinear Whether to print atoms linearly or by element * @return Success of writing. */ public boolean writeFile(File saveFile, boolean append, boolean printLinear) { if (saveFile == null) { return false; } if (vdwH) { logger.info(" Printing hydrogens to van der Waals centers instead of nuclear locations."); } /** * Create StringBuilders for ATOM, ANISOU and TER records that can be * reused. */ StringBuilder sb = new StringBuilder("ATOM "); StringBuilder anisouSB = new StringBuilder("ANISOU"); StringBuilder terSB = new StringBuilder("TER "); for (int i = 6; i < 80; i++) { sb.append(' '); anisouSB.append(' '); terSB.append(' '); } FileWriter fw; BufferedWriter bw; try { File newFile = saveFile; if (!append) { newFile = version(saveFile); } activeMolecularAssembly.setFile(newFile); activeMolecularAssembly.setName(newFile.getName()); logger.log(Level.INFO, " Saving {0}", newFile.getName()); fw = new FileWriter(newFile, append); bw = new BufferedWriter(fw); // ============================================================================= // The CRYST1 record presents the unit cell parameters, space group, and Z // value. If the structure was not determined by crystallographic means, CRYST1 // simply provides the unitary values, with an appropriate REMARK. // // 7 - 15 Real(9.3) a a (Angstroms). // 16 - 24 Real(9.3) b b (Angstroms). // 25 - 33 Real(9.3) c c (Angstroms). // 34 - 40 Real(7.2) alpha alpha (degrees). // 41 - 47 Real(7.2) beta beta (degrees). // 48 - 54 Real(7.2) gamma gamma (degrees). // 56 - 66 LString sGroup Space group. // 67 - 70 Integer z Z value. // ============================================================================= Crystal crystal = activeMolecularAssembly.getCrystal(); if (crystal != null && !crystal.aperiodic()) { Crystal c = crystal.getUnitCell(); if (!listMode) { bw.write(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s\n", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } else { listOutput.add(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } } // ============================================================================= // The SSBOND record identifies each disulfide bond in protein and polypeptide // structures by identifying the two residues involved in the bond. // The disulfide bond distance is included after the symmetry operations at // the end of the SSBOND record. // // 8 - 10 Integer serNum Serial number. // 12 - 14 LString(3) "CYS" Residue name. // 16 Character chainID1 Chain identifier. // 18 - 21 Integer seqNum1 Residue sequence number. // 22 AChar icode1 Insertion code. // 26 - 28 LString(3) "CYS" Residue name. // 30 Character chainID2 Chain identifier. // 32 - 35 Integer seqNum2 Residue sequence number. // 36 AChar icode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry oper for 1st resid // 67 - 72 SymOP sym2 Symmetry oper for 2nd resid // 74 78 Real(5.2) Length Disulfide bond distance // // If SG of cysteine is disordered then there are possible alternate linkages. // wwPDB practice is to put together all possible SSBOND records. This is // problematic because the alternate location identifier is not specified in // the SSBOND record. // ============================================================================= int serNum = 1; Polymer polymers[] = activeMolecularAssembly.getChains(); if (polymers != null) { for (Polymer polymer : polymers) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { if (residue.getName().equalsIgnoreCase("CYS")) { List<Atom> cysAtoms = residue.getAtomList(); Atom SG1 = null; for (Atom atom : cysAtoms) { if (atom.getName().equalsIgnoreCase("SG")) { SG1 = atom; break; } } List<Bond> bonds = SG1.getBonds(); for (Bond bond : bonds) { Atom SG2 = bond.get1_2(SG1); if (SG2.getName().equalsIgnoreCase("SG")) { if (SG1.xyzIndex < SG2.xyzIndex) { bond.energy(false); if (!listMode) { bw.write(format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } else { listOutput.add( format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } } } } } } } } // ============================================================================= // // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X in Angstroms. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y in Angstroms. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z in Angstroms. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= // 1 2 3 4 5 6 7 //123456789012345678901234567890123456789012345678901234567890123456789012345678 //ATOM 1 N ILE A 16 60.614 71.140 -10.592 1.00 7.38 N //ATOM 2 CA ILE A 16 60.793 72.149 -9.511 1.00 6.91 C MolecularAssembly molecularAssemblies[] = this.getMolecularAssemblys(); int serial = 1; // Loop over biomolecular chains if (polymers != null) { for (Polymer polymer : polymers) { currentSegID = polymer.getName(); currentChainID = polymer.getChainID(); sb.setCharAt(21, currentChainID); // Loop over residues ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { String resName = residue.getName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } int resID = residue.getResidueNumber(); sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); // Loop over atoms ArrayList<Atom> residueAtoms = residue.getAtomList(); ArrayList<Atom> backboneAtoms = residue.getBackboneAtoms(); boolean altLocFound = false; for (Atom atom : backboneAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } residueAtoms.remove(atom); } for (Atom atom : residueAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; Polymer altPolymer = altMolecularAssembly.getPolymer(currentChainID, currentSegID, false); Residue altResidue = altPolymer.getResidue(resName, resID, false); backboneAtoms = altResidue.getBackboneAtoms(); residueAtoms = altResidue.getAtomList(); for (Atom atom : backboneAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } residueAtoms.remove(atom); } for (Atom atom : residueAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } } terSB.replace(6, 11, String.format("%5s", Hybrid36.encode(5, serial++))); terSB.replace(12, 16, " "); terSB.replace(16, 26, sb.substring(16, 26)); if (!listMode) { bw.write(terSB.toString()); bw.newLine(); } else { listOutput.add(terSB.toString()); } } } sb.replace(0, 6, "HETATM"); sb.setCharAt(21, 'A'); int resID = 1; Polymer polymer = activeMolecularAssembly.getPolymer('A', "A", false); if (polymer != null) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { int resID2 = residue.getResidueNumber(); if (resID2 >= resID) { resID = resID2 + 1; } } } /** * Loop over molecules, ions and then water. */ ArrayList<Molecule> molecules = activeMolecularAssembly.getMolecules(); for (int i = 0; i < molecules.size(); i++) { Molecule molecule = (Molecule) molecules.get(i); Character chainID = molecule.getChainID(); sb.setCharAt(21, chainID); String resName = molecule.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> moleculeAtoms = molecule.getAtomList(); boolean altLocFound = false; for (Atom atom : moleculeAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altmolecule = altMolecularAssembly.getMolecules().get(i); moleculeAtoms = altmolecule.getAtomList(); for (Atom atom : moleculeAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } ArrayList<MSNode> ions = activeMolecularAssembly.getIons(); for (int i = 0; i < ions.size(); i++) { Molecule ion = (Molecule) ions.get(i); Character chainID = ion.getChainID(); sb.setCharAt(21, chainID); String resName = ion.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> ionAtoms = ion.getAtomList(); boolean altLocFound = false; for (Atom atom : ionAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altion = altMolecularAssembly.getIons().get(i); ionAtoms = altion.getAtomList(); for (Atom atom : ionAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } ArrayList<MSNode> waters = activeMolecularAssembly.getWaters(); for (int i = 0; i < waters.size(); i++) { Molecule water = (Molecule) waters.get(i); Character chainID = water.getChainID(); sb.setCharAt(21, chainID); String resName = water.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> waterAtoms = water.getAtomList(); boolean altLocFound = false; for (Atom atom : waterAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altwater = altMolecularAssembly.getWaters().get(i); waterAtoms = altwater.getAtomList(); for (Atom atom : waterAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } if (!listMode) { bw.write("END"); bw.newLine(); } else { listOutput.add("END"); } bw.close(); } catch (Exception e) { String message = "Exception writing to file: " + saveFile.toString(); logger.log(Level.WARNING, message, e); return false; } return true; }
From source file:ffx.potential.parsers.BiojavaFilter.java
public boolean writeSIFTFile(File saveFile, boolean append, String[] resAndScore) { if (saveFile == null) { return false; }// ww w . j av a2s.com if (vdwH) { logger.info(" Printing hydrogens to van der Waals centers instead of nuclear locations."); } /** * Create StringBuilders for ATOM, ANISOU and TER records that can be * reused. */ StringBuilder sb = new StringBuilder("ATOM "); StringBuilder anisouSB = new StringBuilder("ANISOU"); StringBuilder terSB = new StringBuilder("TER "); for (int i = 6; i < 80; i++) { sb.append(' '); anisouSB.append(' '); terSB.append(' '); } FileWriter fw; BufferedWriter bw; try { File newFile = saveFile; if (!append) { newFile = version(saveFile); } activeMolecularAssembly.setFile(newFile); activeMolecularAssembly.setName(newFile.getName()); logger.log(Level.INFO, " Saving {0}", newFile.getName()); fw = new FileWriter(newFile, append); bw = new BufferedWriter(fw); // ============================================================================= // The CRYST1 record presents the unit cell parameters, space group, and Z // value. If the structure was not determined by crystallographic means, CRYST1 // simply provides the unitary values, with an appropriate REMARK. // // 7 - 15 Real(9.3) a a (Angstroms). // 16 - 24 Real(9.3) b b (Angstroms). // 25 - 33 Real(9.3) c c (Angstroms). // 34 - 40 Real(7.2) alpha alpha (degrees). // 41 - 47 Real(7.2) beta beta (degrees). // 48 - 54 Real(7.2) gamma gamma (degrees). // 56 - 66 LString sGroup Space group. // 67 - 70 Integer z Z value. // ============================================================================= Crystal crystal = activeMolecularAssembly.getCrystal(); if (crystal != null && !crystal.aperiodic()) { Crystal c = crystal.getUnitCell(); if (!listMode) { bw.write(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s\n", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } else { listOutput.add(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } } // ============================================================================= // The SSBOND record identifies each disulfide bond in protein and polypeptide // structures by identifying the two residues involved in the bond. // The disulfide bond distance is included after the symmetry operations at // the end of the SSBOND record. // // 8 - 10 Integer serNum Serial number. // 12 - 14 LString(3) "CYS" Residue name. // 16 Character chainID1 Chain identifier. // 18 - 21 Integer seqNum1 Residue sequence number. // 22 AChar icode1 Insertion code. // 26 - 28 LString(3) "CYS" Residue name. // 30 Character chainID2 Chain identifier. // 32 - 35 Integer seqNum2 Residue sequence number. // 36 AChar icode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry oper for 1st resid // 67 - 72 SymOP sym2 Symmetry oper for 2nd resid // 74 78 Real(5.2) Length Disulfide bond distance // // If SG of cysteine is disordered then there are possible alternate linkages. // wwPDB practice is to put together all possible SSBOND records. This is // problematic because the alternate location identifier is not specified in // the SSBOND record. // ============================================================================= int serNum = 1; Polymer polymers[] = activeMolecularAssembly.getChains(); if (polymers != null) { for (Polymer polymer : polymers) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { if (residue.getName().equalsIgnoreCase("CYS")) { List<Atom> cysAtoms = residue.getAtomList(); Atom SG1 = null; for (Atom atom : cysAtoms) { if (atom.getName().equalsIgnoreCase("SG")) { SG1 = atom; break; } } List<Bond> bonds = SG1.getBonds(); for (Bond bond : bonds) { Atom SG2 = bond.get1_2(SG1); if (SG2.getName().equalsIgnoreCase("SG")) { if (SG1.xyzIndex < SG2.xyzIndex) { bond.energy(false); if (!listMode) { bw.write(format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } else { listOutput.add( format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } } } } } } } } // ============================================================================= // // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X in Angstroms. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y in Angstroms. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z in Angstroms. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= // 1 2 3 4 5 6 7 //123456789012345678901234567890123456789012345678901234567890123456789012345678 //ATOM 1 N ILE A 16 60.614 71.140 -10.592 1.00 7.38 N //ATOM 2 CA ILE A 16 60.793 72.149 -9.511 1.00 6.91 C MolecularAssembly molecularAssemblies[] = this.getMolecularAssemblys(); int serial = 1; // Loop over biomolecular chains if (polymers != null) { for (Polymer polymer : polymers) { currentSegID = polymer.getName(); currentChainID = polymer.getChainID(); sb.setCharAt(21, currentChainID); // Loop over residues ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { String resName = residue.getName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } int resID = residue.getResidueNumber(); int i = 0; String[] entries = null; for (; i < resAndScore.length; i++) { entries = resAndScore[i].split("\\t"); if (!entries[0].equals(entries[0].replaceAll("\\D+", ""))) { String[] subEntries = entries[0].split("[^0-9]"); entries[0] = subEntries[0]; } if (entries[0].equals(String.valueOf(resID)) && !".".equals(entries[1])) { break; } } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); // Loop over atoms ArrayList<Atom> residueAtoms = residue.getAtomList(); boolean altLocFound = false; for (Atom atom : residueAtoms) { if (i != resAndScore.length) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, entries[1]); } else { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; Polymer altPolymer = altMolecularAssembly.getPolymer(currentChainID, currentSegID, false); Residue altResidue = altPolymer.getResidue(resName, resID, false); residueAtoms = altResidue.getAtomList(); for (Atom atom : residueAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { if (i != resAndScore.length) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, entries[1]); } else { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } } } terSB.replace(6, 11, String.format("%5s", Hybrid36.encode(5, serial++))); terSB.replace(12, 16, " "); terSB.replace(16, 26, sb.substring(16, 26)); if (!listMode) { bw.write(terSB.toString()); bw.newLine(); } else { listOutput.add(terSB.toString()); } } } sb.replace(0, 6, "HETATM"); sb.setCharAt(21, 'A'); int resID = 1; Polymer polymer = activeMolecularAssembly.getPolymer('A', "A", false); if (polymer != null) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { int resID2 = residue.getResidueNumber(); if (resID2 >= resID) { resID = resID2 + 1; } } } /** * Loop over molecules, ions and then water. */ ArrayList<Molecule> molecules = activeMolecularAssembly.getMolecules(); for (int i = 0; i < molecules.size(); i++) { Molecule molecule = (Molecule) molecules.get(i); Character chainID = molecule.getChainID(); sb.setCharAt(21, chainID); String resName = molecule.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> moleculeAtoms = molecule.getAtomList(); boolean altLocFound = false; for (Atom atom : moleculeAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altmolecule = altMolecularAssembly.getMolecules().get(i); moleculeAtoms = altmolecule.getAtomList(); for (Atom atom : moleculeAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } ArrayList<MSNode> ions = activeMolecularAssembly.getIons(); for (int i = 0; i < ions.size(); i++) { Molecule ion = (Molecule) ions.get(i); Character chainID = ion.getChainID(); sb.setCharAt(21, chainID); String resName = ion.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> ionAtoms = ion.getAtomList(); boolean altLocFound = false; for (Atom atom : ionAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altion = altMolecularAssembly.getIons().get(i); ionAtoms = altion.getAtomList(); for (Atom atom : ionAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } ArrayList<MSNode> waters = activeMolecularAssembly.getWaters(); for (int i = 0; i < waters.size(); i++) { Molecule water = (Molecule) waters.get(i); Character chainID = water.getChainID(); sb.setCharAt(21, chainID); String resName = water.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> waterAtoms = water.getAtomList(); boolean altLocFound = false; for (Atom atom : waterAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altwater = altMolecularAssembly.getWaters().get(i); waterAtoms = altwater.getAtomList(); for (Atom atom : waterAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } if (!listMode) { bw.write("END"); bw.newLine(); } else { listOutput.add("END"); } bw.close(); } catch (Exception e) { String message = "Exception writing to file: " + saveFile.toString(); logger.log(Level.WARNING, message, e); return false; } return true; }
From source file:ffx.potential.parsers.PDBFilter.java
public boolean writeSIFTFile(File saveFile, boolean append, String[] resAndScore) { if (saveFile == null) { return false; }//ww w . j av a 2s. c om if (vdwH) { logger.info(" Printing hydrogens to van der Waals centers instead of nuclear locations."); } if (nSymOp != 0) { logger.info(String.format(" Printing atoms with symmetry operator %s", activeMolecularAssembly.getCrystal().spaceGroup.getSymOp(nSymOp).toString())); } /** * Create StringBuilders for ATOM, ANISOU and TER records that can be * reused. */ StringBuilder sb = new StringBuilder("ATOM "); StringBuilder anisouSB = new StringBuilder("ANISOU"); StringBuilder terSB = new StringBuilder("TER "); for (int i = 6; i < 80; i++) { sb.append(' '); anisouSB.append(' '); terSB.append(' '); } FileWriter fw; BufferedWriter bw; try { File newFile = saveFile; if (!append && !noVersioning) { newFile = version(saveFile); } activeMolecularAssembly.setFile(newFile); activeMolecularAssembly.setName(newFile.getName()); if (logWrites) { logger.log(Level.INFO, " Saving {0}", newFile.getName()); } fw = new FileWriter(newFile, append); bw = new BufferedWriter(fw); // ============================================================================= // The CRYST1 record presents the unit cell parameters, space group, and Z // value. If the structure was not determined by crystallographic means, CRYST1 // simply provides the unitary values, with an appropriate REMARK. // // 7 - 15 Real(9.3) a a (Angstroms). // 16 - 24 Real(9.3) b b (Angstroms). // 25 - 33 Real(9.3) c c (Angstroms). // 34 - 40 Real(7.2) alpha alpha (degrees). // 41 - 47 Real(7.2) beta beta (degrees). // 48 - 54 Real(7.2) gamma gamma (degrees). // 56 - 66 LString sGroup Space group. // 67 - 70 Integer z Z value. // ============================================================================= Crystal crystal = activeMolecularAssembly.getCrystal(); if (crystal != null && !crystal.aperiodic()) { Crystal c = crystal.getUnitCell(); if (!listMode) { bw.write(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s\n", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } else { listOutput.add(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } } // ============================================================================= // The SSBOND record identifies each disulfide bond in protein and polypeptide // structures by identifying the two residues involved in the bond. // The disulfide bond distance is included after the symmetry operations at // the end of the SSBOND record. // // 8 - 10 Integer serNum Serial number. // 12 - 14 LString(3) "CYS" Residue name. // 16 Character chainID1 Chain identifier. // 18 - 21 Integer seqNum1 Residue sequence number. // 22 AChar icode1 Insertion code. // 26 - 28 LString(3) "CYS" Residue name. // 30 Character chainID2 Chain identifier. // 32 - 35 Integer seqNum2 Residue sequence number. // 36 AChar icode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry oper for 1st resid // 67 - 72 SymOP sym2 Symmetry oper for 2nd resid // 74 78 Real(5.2) Length Disulfide bond distance // // If SG of cysteine is disordered then there are possible alternate linkages. // wwPDB practice is to put together all possible SSBOND records. This is // problematic because the alternate location identifier is not specified in // the SSBOND record. // ============================================================================= int serNum = 1; Polymer polymers[] = activeMolecularAssembly.getChains(); if (polymers != null) { for (Polymer polymer : polymers) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { if (residue.getName().equalsIgnoreCase("CYS")) { List<Atom> cysAtoms = residue.getAtomList(); Atom SG1 = null; for (Atom atom : cysAtoms) { if (atom.getName().equalsIgnoreCase("SG")) { SG1 = atom; break; } } List<Bond> bonds = SG1.getBonds(); for (Bond bond : bonds) { Atom SG2 = bond.get1_2(SG1); if (SG2.getName().equalsIgnoreCase("SG")) { if (SG1.xyzIndex < SG2.xyzIndex) { bond.energy(false); if (!listMode) { bw.write(format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } else { listOutput.add( format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } } } } } } } } // ============================================================================= // // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X in Angstroms. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y in Angstroms. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z in Angstroms. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= // 1 2 3 4 5 6 7 //123456789012345678901234567890123456789012345678901234567890123456789012345678 //ATOM 1 N ILE A 16 60.614 71.140 -10.592 1.00 7.38 N //ATOM 2 CA ILE A 16 60.793 72.149 -9.511 1.00 6.91 C MolecularAssembly molecularAssemblies[] = this.getMolecularAssemblys(); int serial = 1; // Loop over biomolecular chains if (polymers != null) { for (Polymer polymer : polymers) { currentSegID = polymer.getName(); currentChainID = polymer.getChainID(); sb.setCharAt(21, currentChainID); // Loop over residues ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { String resName = residue.getName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } int resID = residue.getResidueNumber(); int i = 0; String[] entries = null; for (; i < resAndScore.length; i++) { entries = resAndScore[i].split("\\t"); if (!entries[0].equals(entries[0].replaceAll("\\D+", ""))) { String[] subEntries = entries[0].split("[^0-9]"); entries[0] = subEntries[0]; } if (entries[0].equals(String.valueOf(resID)) && !".".equals(entries[1])) { break; } } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); // Loop over atoms ArrayList<Atom> residueAtoms = residue.getAtomList(); boolean altLocFound = false; for (Atom atom : residueAtoms) { if (i != resAndScore.length) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, entries[1]); } else { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; Polymer altPolymer = altMolecularAssembly.getPolymer(currentChainID, currentSegID, false); Residue altResidue = altPolymer.getResidue(resName, resID, false); residueAtoms = altResidue.getAtomList(); for (Atom atom : residueAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { if (i != resAndScore.length) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, entries[1]); } else { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } } } terSB.replace(6, 11, String.format("%5s", Hybrid36.encode(5, serial++))); terSB.replace(12, 16, " "); terSB.replace(16, 26, sb.substring(16, 26)); if (!listMode) { bw.write(terSB.toString()); bw.newLine(); } else { listOutput.add(terSB.toString()); } } } sb.replace(0, 6, "HETATM"); sb.setCharAt(21, 'A'); int resID = 1; Polymer polymer = activeMolecularAssembly.getPolymer('A', "A", false); if (polymer != null) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { int resID2 = residue.getResidueNumber(); if (resID2 >= resID) { resID = resID2 + 1; } } } /** * Loop over molecules, ions and then water. */ ArrayList<Molecule> molecules = activeMolecularAssembly.getMolecules(); for (int i = 0; i < molecules.size(); i++) { Molecule molecule = (Molecule) molecules.get(i); Character chainID = molecule.getChainID(); sb.setCharAt(21, chainID); String resName = molecule.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> moleculeAtoms = molecule.getAtomList(); boolean altLocFound = false; for (Atom atom : moleculeAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altmolecule = altMolecularAssembly.getMolecules().get(i); moleculeAtoms = altmolecule.getAtomList(); for (Atom atom : moleculeAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } ArrayList<MSNode> ions = activeMolecularAssembly.getIons(); for (int i = 0; i < ions.size(); i++) { Molecule ion = (Molecule) ions.get(i); Character chainID = ion.getChainID(); sb.setCharAt(21, chainID); String resName = ion.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> ionAtoms = ion.getAtomList(); boolean altLocFound = false; for (Atom atom : ionAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altion = altMolecularAssembly.getIons().get(i); ionAtoms = altion.getAtomList(); for (Atom atom : ionAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } ArrayList<MSNode> waters = activeMolecularAssembly.getWaters(); for (int i = 0; i < waters.size(); i++) { Molecule water = (Molecule) waters.get(i); Character chainID = water.getChainID(); sb.setCharAt(21, chainID); String resName = water.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> waterAtoms = water.getAtomList(); boolean altLocFound = false; for (Atom atom : waterAtoms) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altwater = altMolecularAssembly.getWaters().get(i); waterAtoms = altwater.getAtomList(); for (Atom atom : waterAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeSIFTAtom(atom, serial++, sb, anisouSB, bw, null); } } } } resID++; } if (!listMode) { bw.write("END"); bw.newLine(); } else { listOutput.add("END"); } bw.close(); } catch (Exception e) { String message = "Exception writing to file: " + saveFile.toString(); logger.log(Level.WARNING, message, e); return false; } return true; }
From source file:ffx.potential.parsers.PDBFilter.java
/** * <p>/* ww w . ja va2 s. c o m*/ * writeFile</p> * * @param saveFile a {@link java.io.File} object. * @param append a {@link java.lang.StringBuilder} object. * @param printLinear Whether to print atoms linearly or by element * @return Success of writing. */ public boolean writeFile(File saveFile, boolean append, boolean printLinear) { if (saveFile == null) { return false; } if (vdwH) { logger.info(" Printing hydrogens to van der Waals centers instead of nuclear locations."); } if (nSymOp != 0) { logger.info(String.format(" Printing atoms with symmetry operator %s\n", activeMolecularAssembly.getCrystal().spaceGroup.getSymOp(nSymOp).toString())); } /** * Create StringBuilders for ATOM, ANISOU and TER records that can be * reused. */ StringBuilder sb = new StringBuilder("ATOM "); StringBuilder anisouSB = new StringBuilder("ANISOU"); StringBuilder terSB = new StringBuilder("TER "); StringBuilder model = null; for (int i = 6; i < 80; i++) { sb.append(' '); anisouSB.append(' '); terSB.append(' '); } FileWriter fw; BufferedWriter bw; try { File newFile = saveFile; if (!append) { if (!noVersioning) { newFile = version(saveFile); } } else if (modelsWritten >= 0) { model = new StringBuilder(String.format("MODEL %-4d", ++modelsWritten)); for (int i = 15; i < 80; i++) { model.append(' '); } } activeMolecularAssembly.setFile(newFile); activeMolecularAssembly.setName(newFile.getName()); if (logWrites) { logger.log(Level.INFO, " Saving {0}", newFile.getName()); } fw = new FileWriter(newFile, append); bw = new BufferedWriter(fw); /** * Will come before CRYST1 and ATOM records, but after anything * written by writeFileWithHeader (particularly X-ray refinement * statistics). */ String[] headerLines = activeMolecularAssembly.getHeaderLines(); for (String line : headerLines) { bw.write(String.format("%s\n", line)); } if (model != null) { if (!listMode) { bw.write(model.toString()); bw.newLine(); } else { listOutput.add(model.toString()); } } // ============================================================================= // The CRYST1 record presents the unit cell parameters, space group, and Z // value. If the structure was not determined by crystallographic means, CRYST1 // simply provides the unitary values, with an appropriate REMARK. // // 7 - 15 Real(9.3) a a (Angstroms). // 16 - 24 Real(9.3) b b (Angstroms). // 25 - 33 Real(9.3) c c (Angstroms). // 34 - 40 Real(7.2) alpha alpha (degrees). // 41 - 47 Real(7.2) beta beta (degrees). // 48 - 54 Real(7.2) gamma gamma (degrees). // 56 - 66 LString sGroup Space group. // 67 - 70 Integer z Z value. // ============================================================================= Crystal crystal = activeMolecularAssembly.getCrystal(); if (crystal != null && !crystal.aperiodic()) { Crystal c = crystal.getUnitCell(); if (!listMode) { bw.write(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s\n", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } else { listOutput.add(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10))); } } // ============================================================================= // The SSBOND record identifies each disulfide bond in protein and polypeptide // structures by identifying the two residues involved in the bond. // The disulfide bond distance is included after the symmetry operations at // the end of the SSBOND record. // // 8 - 10 Integer serNum Serial number. // 12 - 14 LString(3) "CYS" Residue name. // 16 Character chainID1 Chain identifier. // 18 - 21 Integer seqNum1 Residue sequence number. // 22 AChar icode1 Insertion code. // 26 - 28 LString(3) "CYS" Residue name. // 30 Character chainID2 Chain identifier. // 32 - 35 Integer seqNum2 Residue sequence number. // 36 AChar icode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry oper for 1st resid // 67 - 72 SymOP sym2 Symmetry oper for 2nd resid // 74 78 Real(5.2) Length Disulfide bond distance // // If SG of cysteine is disordered then there are possible alternate linkages. // wwPDB practice is to put together all possible SSBOND records. This is // problematic because the alternate location identifier is not specified in // the SSBOND record. // ============================================================================= int serNum = 1; Polymer polymers[] = activeMolecularAssembly.getChains(); if (polymers != null) { for (Polymer polymer : polymers) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { if (residue.getName().equalsIgnoreCase("CYS")) { List<Atom> cysAtoms = residue.getAtomList(); Atom SG1 = null; for (Atom atom : cysAtoms) { if (atom.getName().equalsIgnoreCase("SG")) { SG1 = atom; break; } } List<Bond> bonds = SG1.getBonds(); for (Bond bond : bonds) { Atom SG2 = bond.get1_2(SG1); if (SG2.getName().equalsIgnoreCase("SG")) { if (SG1.xyzIndex < SG2.xyzIndex) { bond.energy(false); if (!listMode) { bw.write(format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } else { listOutput.add( format("SSBOND %3d CYS %1s %4s CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue())); } } } } } } } } // ============================================================================= // // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X in Angstroms. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y in Angstroms. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z in Angstroms. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= // 1 2 3 4 5 6 7 //123456789012345678901234567890123456789012345678901234567890123456789012345678 //ATOM 1 N ILE A 16 60.614 71.140 -10.592 1.00 7.38 N //ATOM 2 CA ILE A 16 60.793 72.149 -9.511 1.00 6.91 C MolecularAssembly molecularAssemblies[] = this.getMolecularAssemblys(); int serial = 1; // Loop over biomolecular chains if (polymers != null) { for (Polymer polymer : polymers) { currentSegID = polymer.getName(); currentChainID = polymer.getChainID(); sb.setCharAt(21, currentChainID); // Loop over residues ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { String resName = residue.getName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } int resID = residue.getResidueNumber(); sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); // Loop over atoms ArrayList<Atom> residueAtoms = residue.getAtomList(); ArrayList<Atom> backboneAtoms = residue.getBackboneAtoms(); boolean altLocFound = false; for (Atom atom : backboneAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } residueAtoms.remove(atom); } for (Atom atom : residueAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; Polymer altPolymer = altMolecularAssembly.getPolymer(currentChainID, currentSegID, false); Residue altResidue = altPolymer.getResidue(resName, resID, false); backboneAtoms = altResidue.getBackboneAtoms(); residueAtoms = altResidue.getAtomList(); for (Atom atom : backboneAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } residueAtoms.remove(atom); } for (Atom atom : residueAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } } terSB.replace(6, 11, String.format("%5s", Hybrid36.encode(5, serial++))); terSB.replace(12, 16, " "); terSB.replace(16, 26, sb.substring(16, 26)); if (!listMode) { bw.write(terSB.toString()); bw.newLine(); } else { listOutput.add(terSB.toString()); } } } sb.replace(0, 6, "HETATM"); sb.setCharAt(21, 'A'); int resID = 1; Polymer polymer = activeMolecularAssembly.getPolymer('A', "A", false); if (polymer != null) { ArrayList<Residue> residues = polymer.getResidues(); for (Residue residue : residues) { int resID2 = residue.getResidueNumber(); if (resID2 >= resID) { resID = resID2 + 1; } } } /** * Loop over molecules, ions and then water. */ ArrayList<Molecule> molecules = activeMolecularAssembly.getMolecules(); for (int i = 0; i < molecules.size(); i++) { Molecule molecule = (Molecule) molecules.get(i); Character chainID = molecule.getChainID(); sb.setCharAt(21, chainID); String resName = molecule.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> moleculeAtoms = molecule.getAtomList(); boolean altLocFound = false; for (Atom atom : moleculeAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altmolecule = altMolecularAssembly.getMolecules().get(i); moleculeAtoms = altmolecule.getAtomList(); for (Atom atom : moleculeAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } ArrayList<MSNode> ions = activeMolecularAssembly.getIons(); for (int i = 0; i < ions.size(); i++) { Molecule ion = (Molecule) ions.get(i); Character chainID = ion.getChainID(); sb.setCharAt(21, chainID); String resName = ion.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> ionAtoms = ion.getAtomList(); boolean altLocFound = false; for (Atom atom : ionAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altion = altMolecularAssembly.getIons().get(i); ionAtoms = altion.getAtomList(); for (Atom atom : ionAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } ArrayList<MSNode> waters = activeMolecularAssembly.getWaters(); for (int i = 0; i < waters.size(); i++) { Molecule water = (Molecule) waters.get(i); Character chainID = water.getChainID(); sb.setCharAt(21, chainID); String resName = water.getResidueName(); if (resName.length() > 3) { resName = resName.substring(0, 3); } sb.replace(17, 20, padLeft(resName.toUpperCase(), 3)); sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID))); ArrayList<Atom> waterAtoms = water.getAtomList(); boolean altLocFound = false; for (Atom atom : waterAtoms) { writeAtom(atom, serial++, sb, anisouSB, bw); Character altLoc = atom.getAltLoc(); if (altLoc != null && !altLoc.equals(' ')) { altLocFound = true; } } // Write out alternate conformers if (altLocFound) { for (int ma = 1; ma < molecularAssemblies.length; ma++) { MolecularAssembly altMolecularAssembly = molecularAssemblies[ma]; MSNode altwater = altMolecularAssembly.getWaters().get(i); waterAtoms = altwater.getAtomList(); for (Atom atom : waterAtoms) { if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) { writeAtom(atom, serial++, sb, anisouSB, bw); } } } } resID++; } String end = model != null ? "ENDMDL" : "END"; if (!listMode) { bw.write(end); bw.newLine(); } else { listOutput.add(end); } bw.close(); } catch (Exception e) { String message = "Exception writing to file: " + saveFile.toString(); logger.log(Level.WARNING, message, e); return false; } return true; }
From source file:ffx.potential.parsers.PDBFilter.java
/** * {@inheritDoc}//www .j av a2 s .c o m * * Parse the PDB File * * @return true if the file is read successfully. */ @Override public boolean readFile() { // First atom is #1, to match xyz file format int xyzIndex = 1; setFileRead(false); systems.add(activeMolecularAssembly); List<String> conects = new ArrayList<>(); List<String> links = new ArrayList<>(); List<String> ssbonds = new ArrayList<>(); List<String> structs = new ArrayList<>(); BufferedReader br = null; try { for (File file : files) { currentFile = file; if (mutate) { List<Character> chainIDs = new ArrayList<>(); try (BufferedReader cr = new BufferedReader(new FileReader(file))) { String line = cr.readLine(); while (line != null) { // Replace all tabs w/ 4x spaces line = line.replaceAll("\t", " "); String identity = line; if (line.length() > 6) { identity = line.substring(0, 6); } identity = identity.trim().toUpperCase(); Record record; try { record = Record.valueOf(identity); } catch (Exception e) { /** * Continue until the record is recognized. */ line = cr.readLine(); continue; } switch (record) { case ANISOU: case HETATM: case ATOM: char c22 = line.charAt(21); boolean idFound = false; for (Character chainID : chainIDs) { if (c22 == chainID) { idFound = true; break; } } if (!idFound) { chainIDs.add(c22); } break; } line = cr.readLine(); } if (!chainIDs.contains(mutateChainID)) { if (chainIDs.size() == 1) { logger.warning(String.format( " Chain ID %c for " + "mutation not found: only one chain %c " + "found.", mutateChainID, chainIDs.get(0))); mutateChainID = chainIDs.get(0); } else { logger.warning(String.format( " Chain ID %c for " + "mutation not found: mutation will not " + "proceed.", mutateChainID)); } } } catch (IOException ex) { logger.finest( String.format(" Exception %s in parsing file to find chain IDs", ex.toString())); } } /** * Check that the current file exists and that we can read it. */ if (currentFile == null || !currentFile.exists() || !currentFile.canRead()) { return false; } /** * Open the current file for parsing. */ FileReader fr = new FileReader(currentFile); br = new BufferedReader(fr); /** * Echo the alternate location being parsed. */ if (currentAltLoc == 'A') { logger.info(format(" Reading %s", currentFile.getName())); } else { logger.info(format(" Reading %s alternate location %s", currentFile.getName(), currentAltLoc)); } /** * Reset the current chain and segID. */ currentChainID = null; currentSegID = null; boolean containsInsCode = false; /** * Read the first line of the file. */ String line = br.readLine(); /** * Parse until END or ENDMDL is found, or to the end of the file. */ while (line != null) { // Replace all tabs w/ 4x spaces line = line.replaceAll("\t", " "); String identity = line; if (line.length() > 6) { identity = line.substring(0, 6); } identity = identity.trim().toUpperCase(); Record record; try { record = Record.valueOf(identity); } catch (Exception e) { /** * Continue until the record is recognized. */ line = br.readLine(); continue; } /** * Switch on the known record. */ switch (record) { case ENDMDL: case END: /** * Setting "line" to null will exit the loop. */ line = null; continue; case DBREF: // ============================================================================= // 1 - 6 Record name "DBREF " // 8 - 11 IDcode idCode ID code of this entry. // 13 Character chainID Chain identifier. // 15 - 18 Integer seqBegin Initial sequence number of the // PDB sequence segment. // 19 AChar insertBegin Initial insertion code of the // PDB sequence segment. // 21 - 24 Integer seqEnd Ending sequence number of the // PDB sequence segment. // 25 AChar insertEnd Ending insertion code of the // PDB sequence segment. // 27 - 32 LString database Sequence database name. // 34 - 41 LString dbAccession Sequence database accession code. // 43 - 54 LString dbIdCode Sequence database identification code. // 56 - 60 Integer dbseqBegin Initial sequence number of the // database seqment. // 61 AChar idbnsBeg Insertion code of initial residue of the // segment, if PDB is the reference. // 63 - 67 Integer dbseqEnd Ending sequence number of the // database segment. // 68 AChar dbinsEnd Insertion code of the ending residue of // the segment, if PDB is the reference. // ============================================================================= Character chainID = line.substring(12, 13).toUpperCase().charAt(0); int seqBegin = Integer.parseInt(line.substring(14, 18).trim()); int seqEnd = Integer.parseInt(line.substring(20, 24).trim()); int[] seqRange = dbref.get(chainID); if (seqRange == null) { seqRange = new int[2]; dbref.put(chainID, seqRange); } seqRange[0] = seqBegin; seqRange[1] = seqEnd; break; case SEQRES: // ============================================================================= // 1 - 6 Record name "SEQRES" // 8 - 10 Integer serNum Serial number of the SEQRES record for the // current chain. Starts at 1 and increments // by one each line. Reset to 1 for each chain. // 12 Character chainID Chain identifier. This may be any single // legal character, including a blank which is // is used if there is only one chain. // 14 - 17 Integer numRes Number of residues in the chain. // This value is repeated on every record. // 20 - 22 Residue name resName Residue name. // 24 - 26 Residue name resName Residue name. // 28 - 30 Residue name resName Residue name. // 32 - 34 Residue name resName Residue name. // 36 - 38 Residue name resName Residue name. // 40 - 42 Residue name resName Residue name. // 44 - 46 Residue name resName Residue name. // 48 - 50 Residue name resName Residue name. // 52 - 54 Residue name resName Residue name. // 56 - 58 Residue name resName Residue name. // 60 - 62 Residue name resName Residue name. // 64 - 66 Residue name resName Residue name. // 68 - 70 Residue name resName Residue name. // ============================================================================= activeMolecularAssembly.addHeaderLine(line); chainID = line.substring(11, 12).toUpperCase().charAt(0); int serNum = Integer.parseInt(line.substring(7, 10).trim()); String[] chain = seqres.get(chainID); int numRes = Integer.parseInt(line.substring(13, 17).trim()); if (chain == null) { chain = new String[numRes]; seqres.put(chainID, chain); } int resID = (serNum - 1) * 13; int end = line.length(); for (int start = 19; start + 3 <= end; start += 4) { String res = line.substring(start, start + 3).trim(); if (res == null || res.length() < 1) { break; } chain[resID++] = res; } break; case MODRES: String modResName = line.substring(12, 15).trim(); String stdName = line.substring(24, 27).trim(); modres.put(modResName.toUpperCase(), stdName.toUpperCase()); activeMolecularAssembly.addHeaderLine(line); // ============================================================================= // 1 - 6 Record name "MODRES" // 8 - 11 IDcode idCode ID code of this entry. // 13 - 15 Residue name resName Residue name used in this entry. // 17 Character chainID Chain identifier. // 19 - 22 Integer seqNum Sequence number. // 23 AChar iCode Insertion code. // 25 - 27 Residue name stdRes Standard residue name. // 30 - 70 String comment Description of the residue modification. // ============================================================================= break; case ANISOU: // ============================================================================= // 1 - 6 Record name "ANISOU" // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Insertion code. // 29 - 35 Integer u[0][0] U(1,1) // 36 - 42 Integer u[1][1] U(2,2) // 43 - 49 Integer u[2][2] U(3,3) // 50 - 56 Integer u[0][1] U(1,2) // 57 - 63 Integer u[0][2] U(1,3) // 64 - 70 Integer u[1][2] U(2,3) // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= boolean deleteAnisou = properties.getBoolean("delete-anisou", false); if (deleteAnisou) { break; } Integer serial = Hybrid36.decode(5, line.substring(6, 11)); Character altLoc = line.substring(16, 17).toUpperCase().charAt(0); if (!altLocs.contains(altLoc)) { altLocs.add(altLoc); } if (!altLoc.equals(' ') && !altLoc.equals('A') && !altLoc.equals(currentAltLoc)) { break; } double adp[] = new double[6]; adp[0] = new Integer(line.substring(28, 35).trim()) * 1.0e-4; adp[1] = new Integer(line.substring(35, 42).trim()) * 1.0e-4; adp[2] = new Integer(line.substring(42, 49).trim()) * 1.0e-4; adp[3] = new Integer(line.substring(49, 56).trim()) * 1.0e-4; adp[4] = new Integer(line.substring(56, 63).trim()) * 1.0e-4; adp[5] = new Integer(line.substring(63, 70).trim()) * 1.0e-4; if (atoms.containsKey(serial)) { Atom a = atoms.get(serial); a.setAltLoc(altLoc); a.setAnisou(adp); } else { logger.info( format(" No ATOM record for ANISOU serial number %d has been found.", serial)); logger.info(format(" This ANISOU record will be ignored:\n %s", line)); } break; case ATOM: // ============================================================================= // 1 - 6 Record name "ATOM " // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X in Angstroms. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y in Angstroms. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z in Angstroms. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol, right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= String name; String resName; String segID; int resSeq; boolean printAtom; double d[]; double occupancy; double tempFactor; Atom newAtom; Atom returnedAtom; // If it's a misnamed water, it will fall through to HETATM. if (!line.substring(17, 20).trim().equals("HOH")) { serial = Hybrid36.decode(5, line.substring(6, 11)); name = line.substring(12, 16).trim(); if (name.toUpperCase().contains("1H") || name.toUpperCase().contains("2H") || name.toUpperCase().contains("3H")) { // VERSION3_2 is presently just a placeholder for "anything non-standard". fileStandard = VERSION3_2; } altLoc = line.substring(16, 17).toUpperCase().charAt(0); if (!altLocs.contains(altLoc)) { altLocs.add(altLoc); } if (!altLoc.equals(' ') && !altLoc.equals('A') && !altLoc.equals(currentAltLoc)) { break; } resName = line.substring(17, 20).trim(); chainID = line.substring(21, 22).charAt(0); segID = getSegID(chainID); resSeq = Hybrid36.decode(4, line.substring(22, 26)); char insertionCode = line.charAt(26); if (insertionCode != ' ' && !containsInsCode) { containsInsCode = true; logger.warning(" FFX support for files with " + "insertion codes is experimental. " + "Residues will be renumbered to " + "eliminate insertion codes (52A " + "becomes 53, 53 becomes 54, etc)"); } int offset = inscodeCount.getOrDefault(chainID, 0); String pdbResNum = String.format("%c%d%c", chainID, resSeq, insertionCode); if (!pdbToNewResMap.containsKey(pdbResNum)) { if (insertionCode != ' ') { ++offset; inscodeCount.put(chainID, offset); } resSeq += offset; if (offset != 0) { logger.info(String.format(" Chain %c " + "residue %s-%s renumbered to %c %s-%d", chainID, pdbResNum.substring(1).trim(), resName, chainID, resName, resSeq)); } String newNum = String.format("%c%d", chainID, resSeq); pdbToNewResMap.put(pdbResNum, newNum); } else { resSeq += offset; } printAtom = false; if (mutate && chainID.equals(mutateChainID) && mutateResID == resSeq) { String atomName = name.toUpperCase(); if (atomName.equals("N") || atomName.equals("C") || atomName.equals("O") || atomName.equals("CA")) { printAtom = true; resName = mutateToResname; } else { logger.info( String.format(" Deleting atom %s of %s %d", atomName, resName, resSeq)); break; } } d = new double[3]; d[0] = new Double(line.substring(30, 38).trim()); d[1] = new Double(line.substring(38, 46).trim()); d[2] = new Double(line.substring(46, 54).trim()); occupancy = 1.0; tempFactor = 1.0; try { occupancy = new Double(line.substring(54, 60).trim()); tempFactor = new Double(line.substring(60, 66).trim()); } catch (NumberFormatException | StringIndexOutOfBoundsException e) { // Use default values. if (printMissingFields) { logger.info(" Missing occupancy and b-factors set to 1.0."); printMissingFields = false; } else if (logger.isLoggable(Level.FINE)) { logger.fine(" Missing occupancy and b-factors set to 1.0."); } } newAtom = new Atom(0, name, altLoc, d, resName, resSeq, chainID, occupancy, tempFactor, segID); // Check if this is a modified residue. if (modres.containsKey(resName.toUpperCase())) { newAtom.setModRes(true); } returnedAtom = (Atom) activeMolecularAssembly.addMSNode(newAtom); if (returnedAtom != newAtom) { // A previously added atom has been retained. atoms.put(serial, returnedAtom); if (logger.isLoggable(Level.FINE)) { logger.fine(returnedAtom + " has been retained over\n" + newAtom); } } else { // The new atom has been added. atoms.put(serial, newAtom); // Check if the newAtom took the xyzIndex of a previous alternate conformer. if (newAtom.xyzIndex == 0) { newAtom.setXYZIndex(xyzIndex++); } if (printAtom) { logger.info(newAtom.toString()); } } break; } case HETATM: // ============================================================================= // 1 - 6 Record name "HETATM" // 7 - 11 Integer serial Atom serial number. // 13 - 16 Atom name Atom name. // 17 Character altLoc Alternate location indicator. // 18 - 20 Residue name resName Residue name. // 22 Character chainID Chain identifier. // 23 - 26 Integer resSeq Residue sequence number. // 27 AChar iCode Code for insertion of residues. // 31 - 38 Real(8.3) x Orthogonal coordinates for X. // 39 - 46 Real(8.3) y Orthogonal coordinates for Y. // 47 - 54 Real(8.3) z Orthogonal coordinates for Z. // 55 - 60 Real(6.2) occupancy Occupancy. // 61 - 66 Real(6.2) tempFactor Temperature factor. // 77 - 78 LString(2) element Element symbol; right-justified. // 79 - 80 LString(2) charge Charge on the atom. // ============================================================================= serial = Hybrid36.decode(5, line.substring(6, 11)); name = line.substring(12, 16).trim(); altLoc = line.substring(16, 17).toUpperCase().charAt(0); if (!altLocs.contains(altLoc)) { altLocs.add(altLoc); } if (!altLoc.equals(' ') && !altLoc.equals('A') && !altLoc.equals(currentAltLoc)) { break; } resName = line.substring(17, 20).trim(); chainID = line.substring(21, 22).charAt(0); segID = getSegID(chainID); resSeq = Hybrid36.decode(4, line.substring(22, 26)); char insertionCode = line.charAt(26); if (insertionCode != ' ' && !containsInsCode) { containsInsCode = true; logger.warning(" FFX support for files with " + "insertion codes is experimental. " + "Residues will be renumbered to " + "eliminate insertion codes (52A " + "becomes 53, 53 becomes 54, etc)"); } int offset = inscodeCount.getOrDefault(chainID, 0); String pdbResNum = String.format("%c%d%c", chainID, resSeq, insertionCode); if (!pdbToNewResMap.containsKey(pdbResNum)) { if (insertionCode != ' ') { ++offset; inscodeCount.put(chainID, offset); } resSeq += offset; if (offset != 0) { logger.info(String.format(" Chain %c " + "molecule %s-%s renumbered to %c %s-%d", chainID, pdbResNum.substring(1).trim(), resName, chainID, resName, resSeq)); } String newNum = String.format("%c%d", chainID, resSeq); pdbToNewResMap.put(pdbResNum, newNum); } else { resSeq += offset; } d = new double[3]; d[0] = new Double(line.substring(30, 38).trim()); d[1] = new Double(line.substring(38, 46).trim()); d[2] = new Double(line.substring(46, 54).trim()); occupancy = 1.0; tempFactor = 1.0; try { occupancy = new Double(line.substring(54, 60).trim()); tempFactor = new Double(line.substring(60, 66).trim()); } catch (NumberFormatException | StringIndexOutOfBoundsException e) { // Use default values. if (printMissingFields) { logger.info(" Missing occupancy and b-factors set to 1.0."); printMissingFields = false; } else if (logger.isLoggable(Level.FINE)) { logger.fine(" Missing occupancy and b-factors set to 1.0."); } } newAtom = new Atom(0, name, altLoc, d, resName, resSeq, chainID, occupancy, tempFactor, segID); newAtom.setHetero(true); // Check if this is a modified residue. if (modres.containsKey(resName.toUpperCase())) { newAtom.setModRes(true); } returnedAtom = (Atom) activeMolecularAssembly.addMSNode(newAtom); if (returnedAtom != newAtom) { // A previously added atom has been retained. atoms.put(serial, returnedAtom); if (logger.isLoggable(Level.FINE)) { logger.fine(returnedAtom + " has been retained over\n" + newAtom); } } else { // The new atom has been added. atoms.put(serial, newAtom); newAtom.setXYZIndex(xyzIndex++); } break; case CRYST1: // ============================================================================= // The CRYST1 record presents the unit cell parameters, space group, and Z // value. If the structure was not determined by crystallographic means, CRYST1 // simply provides the unitary values, with an appropriate REMARK. // // 7 - 15 Real(9.3) a a (Angstroms). // 16 - 24 Real(9.3) b b (Angstroms). // 25 - 33 Real(9.3) c c (Angstroms). // 34 - 40 Real(7.2) alpha alpha (degrees). // 41 - 47 Real(7.2) beta beta (degrees). // 48 - 54 Real(7.2) gamma gamma (degrees). // 56 - 66 LString sGroup Space group. // 67 - 70 Integer z Z value. // ============================================================================= double aaxis = new Double(line.substring(6, 15).trim()); double baxis = new Double(line.substring(15, 24).trim()); double caxis = new Double(line.substring(24, 33).trim()); double alpha = new Double(line.substring(33, 40).trim()); double beta = new Double(line.substring(40, 47).trim()); double gamma = new Double(line.substring(47, 54).trim()); int limit = 66; if (line.length() < 66) { limit = line.length(); } String sg = line.substring(55, limit).trim(); properties.addProperty("a-axis", aaxis); properties.addProperty("b-axis", baxis); properties.addProperty("c-axis", caxis); properties.addProperty("alpha", alpha); properties.addProperty("beta", beta); properties.addProperty("gamma", gamma); properties.addProperty("spacegroup", SpaceGroup.pdb2ShortName(sg)); break; case CONECT: // ============================================================================= // 7 - 11 Integer serial Atom serial number // 12 - 16 Integer serial Serial number of bonded atom // 17 - 21 Integer serial Serial number of bonded atom // 22 - 26 Integer serial Serial number of bonded atom // 27 - 31 Integer serial Serial number of bonded atom // // CONECT records involving atoms for which the coordinates are not present // in the entry (e.g., symmetry-generated) are not given. // CONECT records involving atoms for which the coordinates are missing due // to disorder, are also not provided. // ============================================================================= conects.add(line); break; case LINK: // ============================================================================= // The LINK records specify connectivity between residues that is not implied by // the primary structure. Connectivity is expressed in terms of the atom names. // They also include the distance associated with the each linkage following the // symmetry operations at the end of each record. // 13 - 16 Atom name1 Atom name. // 17 Character altLoc1 Alternate location indicator. // 18 - 20 Residue name resName1 Residue name. // 22 Character chainID1 Chain identifier. // 23 - 26 Integer resSeq1 Residue sequence number. // 27 AChar iCode1 Insertion code. // 43 - 46 Atom name2 Atom name. // 47 Character altLoc2 Alternate location indicator. // 48 - 50 Residue name resName2 Residue name. // 52 Character chainID2 Chain identifier. // 53 - 56 Integer resSeq2 Residue sequence number. // 57 AChar iCode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry operator atom 1. // 67 - 72 SymOP sym2 Symmetry operator atom 2. // 74 78 Real(5.2) Length Link distance // ============================================================================= Character a1 = line.charAt(16); Character a2 = line.charAt(46); if (a1 != a2) { logger.info(format(" Ignoring LINK record as alternate locations do not match\n %s.", line)); break; } if (currentAltLoc == 'A') { if ((a1 == ' ' || a1 == 'A') && (a2 == ' ' || a2 == 'A')) { links.add(line); } } else if (a1 == currentAltLoc && a2 == currentAltLoc) { links.add(line); } break; case SSBOND: // ============================================================================= // The SSBOND record identifies each disulfide bond in protein and polypeptide // structures by identifying the two residues involved in the bond. // The disulfide bond distance is included after the symmetry operations at // the end of the SSBOND record. // // 8 - 10 Integer serNum Serial number. // 12 - 14 LString(3) "CYS" Residue name. // 16 Character chainID1 Chain identifier. // 18 - 21 Integer seqNum1 Residue sequence number. // 22 AChar icode1 Insertion code. // 26 - 28 LString(3) "CYS" Residue name. // 30 Character chainID2 Chain identifier. // 32 - 35 Integer seqNum2 Residue sequence number. // 36 AChar icode2 Insertion code. // 60 - 65 SymOP sym1 Symmetry oper for 1st resid // 67 - 72 SymOP sym2 Symmetry oper for 2nd resid // 74 78 Real(5.2) Length Disulfide bond distance // // If SG of cysteine is disordered then there are possible alternate linkages. // wwPDB practice is to put together all possible SSBOND records. This is // problematic because the alternate location identifier is not specified in // the SSBOND record. // // Notes: // SSBOND records may be invalid if chain IDs are reused. // SSBOND records are applied by FFX to the A conformer (not alternate conformers). // ============================================================================= if (currentAltLoc == 'A') { ssbonds.add(line); } break; case HELIX: // ============================================================================= // HELIX records are used to identify the position of helices in the molecule. // Helices are named, numbered, and classified by type. The residues where the // helix begins and ends are noted, as well as the total length. // // 8 - 10 Integer serNum Serial number of the helix. This starts // at 1 and increases incrementally. // 12 - 14 LString(3) helixID Helix identifier. In addition to a serial // number, each helix is given an // alphanumeric character helix identifier. // 16 - 18 Residue name initResName Name of the initial residue. // 20 Character initChainID Chain identifier for the chain containing // this helix. // 22 - 25 Integer initSeqNum Sequence number of the initial residue. // 26 AChar initICode Insertion code of the initial residue. // 28 - 30 Residue name endResName Name of the terminal residue of the helix. // 32 Character endChainID Chain identifier for the chain containing // this helix. // 34 - 37 Integer endSeqNum Sequence number of the terminal residue. // 38 AChar endICode Insertion code of the terminal residue. // 39 - 40 Integer helixClass Helix class (see below). // 41 - 70 String comment Comment about this helix. // 72 - 76 Integer length Length of this helix. // // CLASS NUMBER // TYPE OF HELIX (COLUMNS 39 - 40) // -------------------------------------------------------------- // Right-handed alpha (default) 1 // Right-handed omega 2 // Right-handed pi 3 // Right-handed gamma 4 // Right-handed 3 - 10 5 // Left-handed alpha 6 // Left-handed omega 7 // Left-handed gamma 8 // 2 - 7 ribbon/helix 9 // Polyproline 10 // ============================================================================= case SHEET: // ============================================================================= // SHEET records are used to identify the position of sheets in the molecule. // Sheets are both named and numbered. The residues where the sheet begins and // ends are noted. // // 8 - 10 Integer strand Strand number which starts at 1 for each // strand within a sheet and increases by one. // 12 - 14 LString(3) sheetID Sheet identifier. // 15 - 16 Integer numStrands Number of strands in sheet. // 18 - 20 Residue name initResName Residue name of initial residue. // 22 Character initChainID Chain identifier of initial residue // in strand. // 23 - 26 Integer initSeqNum Sequence number of initial residue // in strand. // 27 AChar initICode Insertion code of initial residue // in strand. // 29 - 31 Residue name endResName Residue name of terminal residue. // 33 Character endChainID Chain identifier of terminal residue. // 34 - 37 Integer endSeqNum Sequence number of terminal residue. // 38 AChar endICode Insertion code of terminal residue. // 39 - 40 Integer sense Sense of strand with respect to previous // strand in the sheet. 0 if first strand, // 1 if parallel,and -1 if anti-parallel. // 42 - 45 Atom curAtom Registration. Atom name in current strand. // 46 - 48 Residue name curResName Registration. Residue name in current strand // 50 Character curChainId Registration. Chain identifier in // current strand. // 51 - 54 Integer curResSeq Registration. Residue sequence number // in current strand. // 55 AChar curICode Registration. Insertion code in // current strand. // 57 - 60 Atom prevAtom Registration. Atom name in previous strand. // 61 - 63 Residue name prevResName Registration. Residue name in // previous strand. // 65 Character prevChainId Registration. Chain identifier in // previous strand. // 66 - 69 Integer prevResSeq Registration. Residue sequence number // in previous strand. // 70 AChar prevICode Registration. Insertion code in // previous strand. // ============================================================================= structs.add(line); break; case MODEL: // Currently, no handling in initial read. default: break; } line = br.readLine(); } br.close(); } xyzIndex--; setFileRead(true); } catch (IOException e) { logger.exiting(PDBFilter.class.getName(), "readFile", e); return false; } /** * Locate disulfide bonds; bond parameters are assigned below. */ List<Bond> ssBondList = locateDisulfideBonds(ssbonds); /** * Record the number of atoms read in from the PDB file before applying * algorithms that may build new atoms. */ int pdbAtoms = activeMolecularAssembly.getAtomArray().length; /** * Build missing backbone atoms in loops. */ buildMissingResidues(xyzIndex); /** * Assign atom types. Missing side-chains atoms and missing hydrogens * will be built in. */ assignAtomTypes(); /** * Assign disulfide bonds parameters and log their creation. */ buildDisulfideBonds(ssBondList); /** * Finally, re-number the atoms if missing atoms were created. */ if (pdbAtoms != activeMolecularAssembly.getAtomArray().length) { numberAtoms(); } return true; }
From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java
public void importRepository(InputStream importFile, Character strategy, UserWcm user) throws WcmAuthorizationException, WcmException { if (user == null) { throw new WcmException("Illegal importRepository() invocation"); }/*from ww w . ja v a2s .c o m*/ if (!user.isManager()) { throw new WcmAuthorizationException("importRepository() is an operation for managers."); } if (importFile == null) { throw new WcmException("InputStream cannot be null"); } // Target folder for uploads String targetFolder; if (System.getProperty(Wcm.UPLOADS.FOLDER) == null) { targetFolder = System.getProperty(Wcm.UPLOADS.DEFAULT) + "/wcm/uploads"; } else { targetFolder = System.getProperty(Wcm.UPLOADS.FOLDER); } // Unzip in a temporal location String temporalFolder = System.getProperty(Wcm.UPLOADS.TMP_DIR) + "/import-" + UUID.randomUUID(); File output = new File(temporalFolder); if (!output.exists()) { output.mkdirs(); } try { FileAux.unzip(new ZipInputStream(importFile), output); } catch (Exception e) { throw new WcmException("Error extracting file " + e.getMessage()); } // Parse gatein-wcm.xml file String gateinWcm = temporalFolder + "/gatein-wcm.xml"; File gateinWcmFile = new File(gateinWcm); if (!gateinWcmFile.exists()) { throw new WcmException("Not gatein-wcm.xml file found in .zip"); } String uploadsFolder = temporalFolder + "/uploads"; File uploadsFolderFile = new File(uploadsFolder); if (!uploadsFolderFile.exists()) { throw new WcmException("Not uploads folder found in .zip"); } ImportParser importParser; try { importParser = new ImportParser(temporalFolder); } catch (Exception e) { throw new WcmException("Error initializing parser " + e.getMessage()); } try { importParser.parse(); } catch (Exception e) { throw new WcmException("Error parsing import file: " + e.getMessage()); } // Update collections // Copy uploads images into data location if (strategy.equals(Wcm.IMPORT.STRATEGY.NEW)) { try { deleteAllRepository(); } catch (Exception e) { throw new WcmException("Error deleting all repository " + e.getMessage()); } } try { Map<Long, Long> mCategories = updateCategories(importParser.getCategories(), strategy); Map<Long, Long> mComments = updateComments(importParser.getComments(), strategy); Map<Long, Long> mPosts = updatePosts(importParser.getPosts(), strategy); Map<Long, Long> mTemplates = updateTemplates(importParser.getTemplates(), strategy); Map<Long, Long> mUploads = updateUploads(importParser.getUploads(), strategy, uploadsFolder, targetFolder); Map<Long, Long> mAcls = updateSecurity(importParser.getAcls(), strategy); updatePostsHistory(importParser.getPostsHistory(), strategy, mPosts); updateTemplatesHistory(importParser.getTemplatesHistory(), strategy, mTemplates); updateUploadsHistory(importParser.getUploadsHistory(), strategy, uploadsFolder, targetFolder, mUploads); updateRelationships(importParser.getRelationships(), strategy, mPosts, mTemplates); updateCategoriesParent(importParser.getCategoriesParent(), mCategories); updateCategoriesPosts(importParser.getCategoriesPosts(), mCategories, mPosts); updateCategoriesTemplates(importParser.getCategoriesTemplates(), mCategories, mTemplates); updateCategoriesUploads(importParser.getCategoriesUploads(), mCategories, mUploads); updateCommentsPost(importParser.getCommentsPost(), mComments, mPosts); updateAclCategories(importParser.getAclsCategories(), mAcls, mCategories); updateAclPosts(importParser.getAclsPosts(), mAcls, mPosts); updateAclUploads(importParser.getAclsUploads(), mAcls, mUploads); updateUploadsLinks(mUploads); updateFilesUploadsLinks(targetFolder, mUploads); } catch (Exception e) { e.printStackTrace(); throw new WcmException("Error upading repository " + e.getMessage()); } }