public static void Run() { // get the primary structure Console.WriteLine("Parsing GRO File"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); PrimaryStructure primaryStructure = GROStructureParser.GetStructure(inputFilePath + inputFileName); stopWatch.Stop(); Console.WriteLine("Structure Parsing Complete [" + stopWatch.ElapsedMilliseconds + " ms]"); // get the structure trajectory int atomCount = XTCTrajectoryParser.GetAtomCount(inputFilePath + trajectoryFileName); if (atomCount == primaryStructure.AtomCount()) { Console.WriteLine("Atom Count matches."); } else { Console.WriteLine("Atom count doesnt match between primary structure and trajectory"); } Stopwatch stopWatch2 = new Stopwatch(); stopWatch2.Start(); PrimaryStructureTrajectory trajectory = XTCTrajectoryParser.GetTrajectory(inputFilePath + trajectoryFileName, 0, 100, 1); stopWatch2.Stop(); Console.WriteLine("Trajectory Parsing Complete [" + stopWatch2.ElapsedMilliseconds + " ms]"); // get the secondary structure for the base primary structure Stopwatch stopWatch3 = new Stopwatch(); stopWatch3.Start(); SecondaryStructure secondaryStructure = SecondaryStructure.CreateFromPrimaryStructure(primaryStructure, strideExePath, tmpFilePath); Console.WriteLine("Main Secondary Structure Parsing Complete [" + stopWatch3.ElapsedMilliseconds + " ms]"); Console.WriteLine(secondaryStructure); // get the secondary structure for a frame of the trajectory Stopwatch stopWatch4 = new Stopwatch(); stopWatch4.Start(); SecondaryStructureTrajectory secondaryStructureTrajectory = new SecondaryStructureTrajectory(primaryStructure, trajectory, strideExePath, tmpFilePath); SecondaryStructure secondaryStructure2 = secondaryStructureTrajectory.GetStructure(50); Console.WriteLine("Secondary Structure Parsing for frame 50 Complete [" + stopWatch3.ElapsedMilliseconds + " ms]"); Console.WriteLine(secondaryStructure2); }
public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency) { StreamReader sr = null; PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory(); try { sr = new StreamReader(filename); // discard first frame, which should be the structure getFrame(sr); // discard frame for (int i = 0; i < startFrame; i++) { getFrame(sr); // discard frame } int framesAdded = 0; int currentFrame = 0; while (framesAdded < numFrames) { currentFrame++; if (currentFrame % frameFrequency == 0) { PrimaryStructureFrame frame = getFrame(sr); if (frame == null) // end of file, no more frames in file { break; } trajectory.AddFrame(frame); framesAdded++; } else { PrimaryStructureFrame frame = getFrame(sr); // discard frame if (frame == null) // end of file, no more frames in file { break; } } } } catch (Exception e) { throw new FileParseException(e.Message); } finally { if (sr != null) { sr.Close(); } } return(trajectory); }
public SecondaryStructureTrajectory(PrimaryStructure primaryStructure, PrimaryStructureTrajectory primaryTrajectory, string strideExePath, string tmpFilePath) { this.primaryStructure = primaryStructure; this.primaryTrajectory = primaryTrajectory; this.strideExePath = strideExePath; this.tmpFilePath = tmpFilePath; secondaryStructuresFrames = new Dictionary <int, SecondaryStructure>(); badFrames = new HashSet <int>(); }
public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency) { PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory(); BinaryReader reader = null; try { int frameCount; int atomCount; bool cellInfo; string title; reader = new BinaryReader(new FileStream(filename, FileMode.Open)); parseDCDHeader(reader, out frameCount, out atomCount, out cellInfo, out title); for (int i = 0; i < startFrame; i++) { discardFrame(reader, cellInfo, atomCount); } int frameIndex = 0; int currentFrame = 0; while (reader.BaseStream.Position != reader.BaseStream.Length && frameIndex < numFrames) { currentFrame++; if (currentFrame % frameFrequency == 0) { PrimaryStructureFrame frame = new PrimaryStructureFrame(); frame.AtomCount = atomCount; //frame.Step = ; //frame.Time = ; parseFrame(reader, cellInfo, frame); trajectory.AddFrame(frame); frameIndex++; } else { discardFrame(reader, cellInfo, atomCount); } } } catch (Exception e) { throw new FileParseException(e.Message); } finally { if (reader != null) { reader.Close(); } } return(trajectory); }
public static PrimaryStructureTrajectory GetTrajectory(string filename, int startFrame, int numFrames, int frameFrequency) { PrimaryStructureTrajectory trajectory = new PrimaryStructureTrajectory(); BinaryReader reader = null; try { reader = new BinaryReader(new FileStream(filename, FileMode.Open)); for (int i = 0; i < startFrame; i++) { discardFrame(reader); } int framesAdded = 0; int currentFrame = 0; while (reader.BaseStream.Position != reader.BaseStream.Length && framesAdded < numFrames) { currentFrame++; if (currentFrame % frameFrequency == 0) { trajectory.AddFrame(getFrame(reader)); framesAdded++; } else { discardFrame(reader); } } } catch (Exception e) { // handle end of file corruption gracefully. if (trajectory.FrameCount() > 0) { return(trajectory); } else { throw new FileParseException(e.Message); } } finally { if (reader != null) { reader.Close(); } } return(trajectory); }
public static void GetTrajectoryColours(string filename, PrimaryStructure model, PrimaryStructureTrajectory trajectory, int startFrame, int numFrames, int frameFrequency) { Stopwatch watch = new Stopwatch(); watch.Start(); StreamReader reader = null; Regex g = new Regex(@"\s*(\d+)\s*(\d+\.?\d*)"); try { reader = new StreamReader(filename); discardFrames(reader, startFrame); List <float[]> colourFrames = new List <float[]>(); int colourFrameNumber = -1; int atomIndex = 0; float colour = 0; float[] colourFrame = null; string line; while ((line = readLine(reader)) != null && colourFrames.Count < numFrames) { if (line.Trim().Length == 0) // is empty string? { continue; } // discard everything but matches Match m = g.Match(line); if (m.Success) { atomIndex = int.Parse(m.Groups[1].Value); colour = float.Parse(m.Groups[2].Value); if (atomIndex == 1) { colourFrameNumber++; // save colours if (colourFrame != null) { colourFrames.Add(colourFrame); colourFrame = null; } if (colourFrameNumber % frameFrequency == 0) { // initialise new colour arrary colourFrame = new float[model.AtomCount()]; for (int i = 0; i < colourFrame.Length; i++) { colourFrame[i] = DEFAULT_COLOUR_VALUE; } } } if (colourFrame != null) { if (atomIndex > 0 && atomIndex <= colourFrame.Length) { colourFrame[atomIndex - 1] = colour; } } } } PrimaryStructureFrame currentFrame = null; int frameNumber = 0; // copy all colour frames to trajectory frames foreach (float[] frame in colourFrames) { currentFrame = trajectory.GetFrame(frameNumber); currentFrame.Colours = frame; frameNumber++; // if we've run out of trajectory frames then stop copying if (frameNumber >= trajectory.FrameCount()) { break; } } // if more trajectory frames than colour frames fill in rest of trajectory frames with default colours float[] colours = new float[model.AtomCount()]; for (int i = 0; i < colours.Length; i++) { colours[i] = 0f; } foreach (PrimaryStructureFrame frame in trajectory.GetFrames()) { if (frame.Colours == null) { frame.Colours = colours; } } } catch (Exception e) { throw new FileParseException(e.Message); } finally { if (reader != null) { reader.Close(); } } }
public static void GetTrajectoryColours(string filename, PrimaryStructure model, PrimaryStructureTrajectory trajectory) { GetTrajectoryColours(filename, model, trajectory, 0, DEFAULT_FRAME_READ, 1); }