/// <summary> /// Method which assigns van der Waals radii to the biopolymer /// default org/openscience/cdk/config/data/pdb_atomtypes.xml /// stored in the variable string vanDerWaalsFile. /// </summary> public void AssignVdWRadiiToProtein() { AtomTypeFactory atf = null; var atoms = Protein.Atoms.ToArray(); try { atf = AtomTypeFactory.GetInstance(VanDerWaalsFile); } catch (Exception ex1) { Console.Out.WriteLine($"Problem with AtomTypeFactory due to:{ex1.ToString()}"); } for (int i = 0; i < atoms.Length; i++) { try { atf.Configure(atoms[i]); } catch (Exception ex2) { Trace.TraceError($"Problem with atf.configure due to:{ex2.ToString()}"); } } }
/// <summary> /// Creates an <see cref="PDBAtom"/> and sets properties to their values from /// the ATOM or HETATM record. If the line is shorter than 80 characters, the /// information past 59 characters is treated as optional. If the line is /// shorter than 59 characters, a <see cref="ApplicationException"/> is thrown. /// </summary> /// <param name="cLine">the PDB ATOM or HEATATM record.</param> /// <param name="lineLength"></param> /// <returns>the <see cref="PDBAtom"/>created from the record.</returns> /// <exception cref="InvalidDataException">if the line is too short (less than 59 characters).</exception> private PDBAtom ReadAtom(string cLine, int lineLength) { // a line can look like (two in old format, then two in new format): // // 1 2 3 4 5 6 7 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 // ATOM 1 O5* C A 1 20.662 36.632 23.475 1.00 10.00 114D 45 // ATOM 1186 1H ALA 1 10.105 5.945 -6.630 1.00 0.00 1ALE1288 // ATOM 31 CA SER A 3 -0.891 17.523 51.925 1.00 28.64 C // HETATM 3486 MG MG A 302 24.885 14.008 59.194 1.00 29.42 MG+2 // // note: the first two examples have the PDBID in col 72-75 // note: the last two examples have the element symbol in col 76-77 // note: the last (Mg hetatm) has a charge in col 78-79 if (lineLength < 59) { throw new InvalidDataException("PDBReader error during ReadAtom(): line too short"); } var isHetatm = cLine.StartsWith("HETATM", StringComparison.Ordinal); var atomName = cLine.Substring(12, 4).Trim(); var resName = cLine.Substring(17, 3).Trim(); var symbol = ParseAtomSymbol(cLine); if (symbol == null) { HandleError($"Cannot parse symbol from {atomName}"); } var oAtom = new PDBAtom(symbol, new Vector3(double.Parse(cLine.Substring(30, 8), NumberFormatInfo.InvariantInfo), double.Parse(cLine.Substring(38, 8), NumberFormatInfo.InvariantInfo), double.Parse(cLine.Substring(46, 8), NumberFormatInfo.InvariantInfo))); if (useHetDictionary.IsSet && isHetatm) { var cdkType = TypeHetatm(resName, atomName); oAtom.AtomTypeName = cdkType; if (cdkType != null) { try { cdkAtomTypeFactory.Configure(oAtom); } catch (CDKException) { Trace.TraceWarning("Could not configure", resName, " ", atomName); } } } oAtom.Record = cLine; oAtom.Serial = int.Parse(cLine.Substring(6, 5).Trim(), NumberFormatInfo.InvariantInfo); oAtom.Name = atomName.Trim(); oAtom.AltLoc = cLine.Substring(16, 1).Trim(); oAtom.ResName = resName; oAtom.ChainID = cLine.Substring(21, 1).Trim(); oAtom.ResSeq = cLine.Substring(22, 4).Trim(); oAtom.ICode = cLine.Substring(26, 1).Trim(); if (useHetDictionary.IsSet && isHetatm) { oAtom.Id = oAtom.ResName + "." + atomName; } else { oAtom.AtomTypeName = oAtom.ResName + "." + atomName; } if (lineLength >= 59) { var frag = cLine.Substring(54, Math.Min(lineLength - 54, 6)).Trim(); if (frag.Length > 0) { oAtom.Occupancy = double.Parse(frag, NumberFormatInfo.InvariantInfo); } } if (lineLength >= 65) { var frag = cLine.Substring(60, Math.Min(lineLength - 60, 6)).Trim(); if (frag.Length > 0) { oAtom.TempFactor = double.Parse(frag, NumberFormatInfo.InvariantInfo); } } if (lineLength >= 75) { oAtom.SegID = cLine.Substring(72, Math.Min(lineLength - 72, 4)).Trim(); } if (lineLength >= 79) { string frag; if (lineLength >= 80) { frag = cLine.Substring(78, 2).Trim(); } else { frag = cLine.Substring(78); } if (frag.Length > 0) { // see Format_v33_A4.pdf, p. 178 if (frag.EndsWithChar('-') || frag.EndsWithChar('+')) { var aa = frag.ToCharArray(); Array.Reverse(aa); oAtom.Charge = double.Parse(new string(aa), NumberFormatInfo.InvariantInfo); } else { oAtom.Charge = double.Parse(frag, NumberFormatInfo.InvariantInfo); } } } // *********************************************************************************** // It sets a flag in the property content of an atom, which is used when // bonds are created to check if the atom is an OXT-record => needs // special treatment. var oxt = cLine.Substring(13, 3).Trim(); if (string.Equals(oxt, "OXT", StringComparison.Ordinal)) { oAtom.Oxt = true; } else { oAtom.Oxt = false; } // ********************************************************************************** return(oAtom); }