public static void Run() { Console.WriteLine("Parsing PBD File"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); PrimaryStructure model = PDBStructureParser.GetPrimaryStructure(inputFilePath + inputFileName); stopWatch.Stop(); Console.WriteLine("Structure Parsing Complete [" + stopWatch.ElapsedMilliseconds + " ms]"); Console.WriteLine("Atom Count: " + model.Atoms().Count); Console.WriteLine("Running Stride Analysis"); stopWatch = new Stopwatch(); stopWatch.Start(); StrideAnalysis stride = new StrideAnalysis(exePath); SecondaryStructure structure = stride.GetSecondaryStructure(inputFilePath + inputFileName); // Console.WriteLine("Secondary structure:\n\n" + structure); stopWatch.Stop(); Console.WriteLine("Processing complete [" + stopWatch.ElapsedMilliseconds + " ms]"); Console.WriteLine("End Testing Stride"); foreach (Chain chain in model.Chains()) { Console.WriteLine("Chain ID: " + chain.ID); if (chain.ResidueType != StandardResidue.AminoAcid) { Console.WriteLine("Not a protein chain"); continue; } foreach (Residue residue in chain.MainChainResidues) { if (residue.CarbonylOxygen == null) { Console.WriteLine("Residue ID: " + residue.ID + " has no oxygen"); } SecondaryStructureInfomation structureInfo = structure.GetStructureInformation(residue.Index); if (structureInfo == null) { Console.WriteLine("Couldn't find structure info for residue index: " + residue.Index); } else { Console.WriteLine("Residue [" + residue.ID + "][" + residue.Name + "] has structure [" + structureInfo.ToString() + "] and Alpha Carbon: " + residue.AlphaCarbon); } } } }
// private static string inputFileFileName = @"lipoprotein_DS.pdb"; //private static string inputFileFileName = @"lipoprotein.pdb"; //private static string inputFilePath = @"D:\Molecule Examples\PDB Example Files\"; //private static string inputFileFileName = @"Zika_Virus_5ire.pdb"; public static void Run() { Console.WriteLine("Parsing PBD File"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // PrimaryStructure model = PDBStructureParser.GetStructure(inputFilePath + inputFileFileName); PrimaryStructure model = GROStructureParser.GetStructure(inputFilePath + inputFileFileName); stopWatch.Stop(); Console.WriteLine("Structure Parsing Complete [" + stopWatch.ElapsedMilliseconds + " ms]"); Console.WriteLine("Atom Count: " + model.Atoms().Count); // Console.WriteLine(model.ToString()); foreach (Chain chain in model.Chains()) { Console.WriteLine("Chain " + chain.ID + ": ");// + residue.ToString()); if (chain.ResidueType == StandardResidue.AminoAcid) { foreach (Residue residue in chain.MainChainResidues) { Console.WriteLine(residue); } //foreach (Atom mainChainAtom in chain.Value.MainChainAtoms) { // Console.WriteLine(mainChainAtom); //} } else { Console.WriteLine("Chain " + chain.ID + " is not a protein chain"); //foreach (KeyValuePair<int, Residue> residue in chain.Value.Residues) { // Console.WriteLine(residue.Value.ResidueType.ToString()); //} } } }
public static void ParseGromacs() { Console.WriteLine("Parsing GRO File"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); PrimaryStructure model = GROStructureParser.GetStructure(filepath + structureFile); stopWatch.Stop(); Console.WriteLine("Structure Parsing Complete [" + stopWatch.ElapsedMilliseconds + " ms]"); Console.WriteLine("Atom Count: " + model.Atoms().Count); foreach (Atom atom in model.Atoms()) { Console.WriteLine("Atom " + atom.Index + ": " + atom.ToString()); } Console.WriteLine("\n---------------------\n"); Dictionary <Element, Dictionary <int, Atom> > atomSet = model.GetAtomsByElement(); foreach (KeyValuePair <Element, Dictionary <int, Atom> > set in atomSet) { Element element = set.Key; Console.WriteLine("Element: " + element.ToString()); Dictionary <int, Atom> atoms = set.Value; foreach (KeyValuePair <int, Atom> atom in atoms) { Console.WriteLine("Atom: " + atom.Value.ToString()); } } foreach (Chain chain in model.Chains()) { Console.WriteLine("\n---------------------\n"); Console.WriteLine("Chain ID: " + chain.ID); Console.WriteLine("Chain Residue Count: " + chain.Residues.Count); foreach (Residue residue in chain.Residues) { Console.WriteLine("ResidueID: " + residue.ID + ", Residue Name: " + residue.Name); } } stopWatch.Reset(); stopWatch.Start(); int NumberOfProcessorCores = 6; Dictionary <int, Bond> bonds = model.GenerateBonds(NumberOfProcessorCores); Console.WriteLine("Bond generation complete [" + stopWatch.ElapsedMilliseconds + " ms]"); int count = 0; foreach (KeyValuePair <int, Bond> bond in bonds) { Atom atom1 = model.Atoms()[bond.Value.Atom1Index]; Atom atom2 = model.Atoms()[bond.Value.Atom2Index]; if ((atom1.Element == Element.O && atom2.Element == Element.H) || (atom2.Element == Element.O && atom1.Element == Element.H)) { Console.WriteLine("O-H bond found. Distance: " + Vector3.Distance(atom1.Position, atom2.Position)); count++; if (count > 5) { break; } } } Console.WriteLine("Getting frame count from trajectory file"); stopWatch.Reset(); stopWatch.Start(); count = XTCTrajectoryParser.GetFrameCount(filepath + trajectoryFile); stopWatch.Stop(); Console.WriteLine("Frame count complete [" + stopWatch.ElapsedMilliseconds + " ms]"); Console.WriteLine("Frames counted: " + count); }
/// <summary> /// generate a box from a provided Primary Structure /// </summary> /// <returns></returns> public BoundingBox(PrimaryStructure structure, bool flipZ = false) { float minx = 0; float maxx = 0; float miny = 0; float maxy = 0; float minz = 0; float maxz = 0; bool firstAtom = true; foreach (Atom atom in structure.Atoms()) { if (firstAtom) { minx = atom.Position.x; maxx = atom.Position.x; miny = atom.Position.y; maxy = atom.Position.y; minz = atom.Position.z; maxz = atom.Position.z; firstAtom = false; } else { if (atom.Position.x < minx) { minx = atom.Position.x; } if (atom.Position.x > maxx) { maxx = atom.Position.x; } if (atom.Position.y < miny) { miny = atom.Position.y; } if (atom.Position.y > maxy) { maxy = atom.Position.y; } if (atom.Position.z < minz) { minz = atom.Position.z; } if (atom.Position.z > maxz) { maxz = atom.Position.z; } } } float edgeBuffer = 0.1f; minx -= edgeBuffer; maxx += edgeBuffer; miny -= edgeBuffer; maxy += edgeBuffer; minz -= edgeBuffer; maxz += edgeBuffer; if (flipZ) { minz *= -1; maxz *= -1; } setVectors(minx, maxx, miny, maxy, minz, maxz); }
private static PrimaryStructure GetFrame(StreamReader sr) { PrimaryStructure model; // todo: improve file format error handling for misformatted files try { model = new PrimaryStructure(); string titleLine = sr.ReadLine(); // remove any blank lines before title line while (titleLine != null && titleLine.Trim().Equals("")) { titleLine = sr.ReadLine(); } if (titleLine == null) { return(null); } model.Title = titleLine; model.Time = 0; Regex g = new Regex(@"\st=\s*(\d+\.?\d*)"); Match m = g.Match(titleLine); if (m.Success) { string frameTimeString = m.Groups[1].Value; model.Time = float.Parse(frameTimeString); // Console.WriteLine("Success parsing[" + titleLine + "] for frame time"); } else { // no frame time in header. Assume structure file, leave frame time at 0; // return false; } int residueIndex = 0; int chainIndex = 0; Chain chain = null; Residue residue = null; int currentResidueID = -1; Residue lastResidue = null; int atomCount = Int32.Parse(sr.ReadLine().Trim()); for (int i = 0; i < atomCount; i++) { string atomLine = sr.ReadLine(); if (atomLine == null) // if something is wrong with the file, i.e. ends before total atom count { break; } // if atom residue number not the existing residue number store the existing residue and instantiate new residue int atomResidueID = int.Parse(atomLine.Substring(0, 5).Trim()); if (atomResidueID != currentResidueID) { // store residue - first time here will be null if (residue != null) { model.AddResidue(residueIndex, residue); if (chain != null) { chain.AddResidue(residueIndex, residue); } } residueIndex++; currentResidueID = atomResidueID; string residueName = atomLine.Substring(5, 5).Trim(); lastResidue = residue; residue = new Residue(residueIndex, currentResidueID, residueName); // Residue type changes used to capture chain information. May not be 100% accurate but not parsing topology files so options are limited. // Also checking to see if last two atoms before end of amino acid were Oxygen, signifying a chain terminator if ((lastResidue == null || residue.ResidueType != lastResidue.ResidueType) || (lastResidue.ResidueType == StandardResidue.AminoAcid && model.Atoms()[i - 1].Element == Element.O && model.Atoms()[i - 2].Element == Element.O)) { if (chain != null) { model.AddChain(chain); } chainIndex++; chain = new Chain(chainIndex, chainIndex.ToString()); } } int atomIndex = i; int atomID = int.Parse((atomLine.Substring(15, 5)).Trim()); string atomName = atomLine.Substring(10, 5).Trim(); Element element = ElementHelper.Parse(atomName); Vector3 position = new Vector3(); position.x = float.Parse(atomLine.Substring(20, 8)); position.y = float.Parse(atomLine.Substring(28, 8)); position.z = float.Parse(atomLine.Substring(36, 8)); Atom atom = new Atom(atomIndex, atomID, atomName, element, position); // check for and store main chain elements. if (residue.ResidueType != StandardResidue.None) { switch (atom.Name) { case "N": residue.AmineNitrogen = atom; break; case "CA": residue.AlphaCarbon = atom; break; case "C": residue.CarbonylCarbon = atom; break; case "O": case "O1": case "OT1": residue.CarbonylOxygen = atom; break; } } atom.ResidueIndex = residueIndex; atom.ResidueID = currentResidueID; atom.ResidueName = residue.Name; atom.ResidueType = residue.ResidueType; atom.ChainID = chainIndex.ToString(); residue.Atoms.Add(atomIndex, atom); model.AddAtom(atomIndex, atom); } if (residue != null) { model.AddResidue(residueIndex, residue); if (chain != null) { chain.AddResidue(residueIndex, residue); } } if (chain != null) { model.AddChain(chain); } // Parse box vectors. // todo: test and make this more robust for various string lengths float[] vertices = parseBoxLine(sr.ReadLine()); model.OriginalBoundingBox = new BoundingBox(vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5], vertices[6], vertices[7], vertices[8]); } catch (Exception e) { throw new FileParseException(e.Message); } return(model); }