private SecondaryStructure CalculateSecondaryStructure(int frameNumber) { string tmpFileName = tmpFilePath + @"tempStructure_" + frameNumber + ".pdb"; PDBStructureCreator pdbCreator = new PDBStructureCreator(primaryStructure, primaryTrajectory.GetFrame(frameNumber)); pdbCreator.CreatePDBFile(tmpFileName, true, true, true); SecondaryStructure frame = null; try { StrideAnalysis stride = new StrideAnalysis(strideExePath); frame = stride.GetSecondaryStructure(tmpFileName); } catch (StrideException ex) { throw new StrideException(ex.Message); } finally { FileUtil.DeleteFile(tmpFileName); } return(frame); }
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(); } } }