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 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(); } } }