+ /*
+ * If > 99% 'P', flag as nucleotide; note the count doesn't include the last
+ * residue
+ */
+ if (residues.size() > 1 && (numNa / (residues.size() - 1) > 0.99))
+ {
+ isNa = true;
+ }
+ }
+
+ /**
+ * Construct a bond from atom1 to atom2 and add it to the list of bonds for
+ * this chain
+ *
+ * @param at1
+ * @param at2
+ */
+ public void makeBond(Atom at1, Atom at2)
+ {
+ bonds.addElement(new Bond(at1, at2));
+ }
+
+ /**
+ * Traverses the list of atoms and
+ * <ul>
+ * <li>constructs a list of Residues, each containing all the atoms that share
+ * the same residue number</li>
+ * <li>adds a RESNUM sequence feature for each position</li>
+ * <li>creates the sequence string</li>
+ * <li>determines if nucleotide</li>
+ * <li>saves the residue number of the first atom as 'offset'</li>
+ * <li>adds temp factor annotation if the flag is set to do so</li>
+ * </ul>
+ *
+ * @param visibleChainAnnotation
+ */
+ public void makeResidueList(boolean visibleChainAnnotation)
+ {
+ int count = 0;
+ Object symbol;
+ boolean deoxyn = false;
+ boolean nucleotide = false;
+ StringBuilder seq = new StringBuilder(256);
+ Vector<SequenceFeature> resFeatures = new Vector<>();
+ Vector<Annotation> resAnnotation = new Vector<>();
+ int iSize = atoms.size() - 1;
+ int resNumber = -1;
+ char insCode = ' ';
+
+ for (int i = 0; i <= iSize; i++)
+ {
+ Atom tmp = atoms.elementAt(i);
+ resNumber = tmp.resNumber;
+ insCode = tmp.insCode;
+
+ int res = resNumber;
+ char ins = insCode;
+
+ if (i == 0)
+ {
+ offset = resNumber;
+ }
+
+ Vector<Atom> resAtoms = new Vector<>();
+ // Add atoms to a vector while the residue number
+ // remains the same as the first atom's resNumber (res)
+ while ((resNumber == res) && (ins == insCode) && (i < atoms.size()))
+ {
+ resAtoms.add(atoms.elementAt(i));
+ i++;
+
+ if (i < atoms.size())
+ {
+ resNumber = atoms.elementAt(i).resNumber;
+ insCode = atoms.elementAt(i).insCode;
+ }
+ else
+ {
+ resNumber++;
+ }
+ }
+
+ // We need this to keep in step with the outer for i = loop
+ i--;
+
+ // Add inserted residues as features to the base residue
+ Atom currAtom = resAtoms.get(0);
+ if (currAtom.insCode != ' ' && !residues.isEmpty()
+ && residues.lastElement().atoms
+ .get(0).resNumber == currAtom.resNumber)
+ {
+ String desc = currAtom.resName + ":" + currAtom.resNumIns + " "
+ + pdbid + id;
+ SequenceFeature sf = new SequenceFeature("INSERTION", desc, offset
+ + count - 1, offset + count - 1, "PDB_INS");
+ resFeatures.addElement(sf);
+ residues.lastElement().atoms.addAll(resAtoms);
+ }
+ else
+ {
+ // Make a new Residue object with the new atoms vector
+ residues.addElement(new Residue(resAtoms, resNumber - 1, count));
+
+ Residue tmpres = residues.lastElement();
+ Atom tmpat = tmpres.atoms.get(0);
+ // Make A new SequenceFeature for the current residue numbering
+ String desc = tmpat.resName
+ + ":" + tmpat.resNumIns + " " + pdbid + id;
+ SequenceFeature sf = new SequenceFeature(RESNUM_FEATURE, desc,
+ offset + count, offset + count, pdbid);
+ resFeatures.addElement(sf);
+ resAnnotation.addElement(new Annotation(tmpat.tfactor));
+ // Keep totting up the sequence
+
+ if ((symbol = ResidueProperties.getAA3Hash()
+ .get(tmpat.resName)) == null)
+ {
+ String nucname = tmpat.resName.trim();
+ // use the aaIndex rather than call 'toLower' - which would take a bit
+ // more time.
+ deoxyn = nucname.length() == 2
+ && ResidueProperties.aaIndex[nucname
+ .charAt(0)] == ResidueProperties.aaIndex['D'];
+ if (tmpat.name.equalsIgnoreCase("CA")
+ || ResidueProperties.nucleotideIndex[nucname
+ .charAt((deoxyn ? 1 : 0))] == -1)
+ {
+ char r = ResidueProperties.getSingleCharacterCode(
+ ResidueProperties.getCanonicalAminoAcid(tmpat.resName));
+ seq.append(r == '0' ? 'X' : r);
+ // System.err.println("PDBReader:Null aa3Hash for " +
+ // tmpat.resName);
+ }
+ else
+ {
+ // nucleotide flag
+ nucleotide = true;
+ seq.append(nucname.charAt((deoxyn ? 1 : 0)));
+ }
+ }
+ else
+ {
+ if (nucleotide)
+ {
+ System.err.println(
+ "Warning: mixed nucleotide and amino acid chain.. its gonna do bad things to you!");
+ }
+ seq.append(ResidueProperties.aa[((Integer) symbol).intValue()]);
+ }
+ count++;
+ }
+ }