public Run GenerateRun() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; _telemetry.Write(module, "Verbose", "Called"); //start off progress monitoring Progress pb = new Progress(); pb.TopLeft = _topLeft; //lists of objects for drawing _atomLabelCharacters = new List <AtomLabelCharacter>(); _bondLines = new List <BondLine>(); Stopwatch swr = new Stopwatch(); Stopwatch sw = new Stopwatch(); //Create a run Run run = new Run(); sw.Start(); swr.Start(); //set the median bond length _medianBondLength = GeometryTool.GetMedianBondLength2D(_chemistryModel.AllBonds); int moleculeNo = 0; foreach (Molecule mol in _chemistryModel.Molecules) { moleculeNo++; // Step 1- gather the atom information together Debug.WriteLine($"{module} Starting Step 1"); //_telemetry.Write(module, "Verbose", $"Starting Step 1 for molecule {moleculeNo}"); ProcessAtoms(mol, pb, moleculeNo, _pt); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", $"Step 1 for molecule {moleculeNo} took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); // Step 2- gather the bond information together Debug.WriteLine($"{module} Starting Step 2"); //_telemetry.Write(module, "Verbose", $"Starting Step 2 for molecule {moleculeNo}"); ProcessBonds(mol, pb, moleculeNo); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", $"Step 2 for molecule {moleculeNo} took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); if (_options.ShowRingCentres) { // Save Rings for later foreach (Ring ring in mol.Rings) { _rings.Add(ring.UniqueID, ring); } } } Debug.WriteLine($"{module} Starting Step 3"); //_telemetry.Write(module, "Verbose", "Starting Step 3"); IncreaseCanvasSize(); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 3 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); if (_options.ClipLines) { Debug.WriteLine($"{module} Starting Step 4"); //_telemetry.Write(module, "Verbose", "Starting Step 4"); #region Step 4 - Shrink bond lines ShrinkBondLinesPass1(pb); ShrinkBondLinesPass2(pb); #endregion Step 4 - Shrink bond lines Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 4 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); } Debug.WriteLine($"{module} Starting Step 5"); //_telemetry.Write(module, "Verbose", "Starting Step 5"); #region Step 5 - Create main OoXml drawing objects Drawing drawing1 = new Drawing(); A.Graphic graphic1 = CreateGraphic(); A.GraphicData graphicData1 = CreateGraphicData(); Wpg.WordprocessingGroup wordprocessingGroup1 = new Wpg.WordprocessingGroup(); // Create Inline Drawing using canvas extents Wp.Inline inline1 = CreateInline(graphicData1, wordprocessingGroup1); #endregion Step 5 - Create main OoXml drawing objects Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 5 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); #region Step 5a - Diagnostics if (_options.ShowMoleculeBoundingBoxes) { DrawBox(wordprocessingGroup1, _modelExtents, "00ff00", 1); foreach (Molecule mol in _chemistryModel.Molecules) { DrawBox(wordprocessingGroup1, mol.BoundingBox, "0000ff", 1); DrawBox(wordprocessingGroup1, MoleculeExtents(mol), "ff0000", 1); } DrawBox(wordprocessingGroup1, _canvasExtents, "000000", 1); } if (_options.ShowRingCentres) { ShowRingCentres(wordprocessingGroup1); } if (_options.ShowAtomPositions) { ShowAtomCentres(wordprocessingGroup1); } if (_options.ShowHulls) { ShowConvexHulls(wordprocessingGroup1); } #endregion Step 5a - Diagnostics Debug.WriteLine($"{module} Starting Step 6"); //_telemetry.Write(module, "Verbose", "Starting Step 6"); #region Step 6 - Create and append OoXml objects for all Bond Lines AppendBondOoxml(pb, wordprocessingGroup1); #endregion Step 6 - Create and append OoXml objects for all Bond Lines Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 6 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); Debug.WriteLine($"{module} Starting Step 7"); //_telemetry.Write(module, "Verbose", "Starting Step 7"); #region Step 7 - Create and append OoXml objects for Atom Labels AppendAtomLabelOoxml(pb, wordprocessingGroup1); #endregion Step 7 - Create and append OoXml objects for Atom Labels Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 7 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); Debug.WriteLine($"{module} Starting Step 8"); //_telemetry.Write(module, "Verbose", "Starting Step 8"); #region Step 8 - Append OoXml drawing objects to OoXml run object AppendAllOoXml(graphicData1, wordprocessingGroup1, graphic1, inline1, drawing1, run); #endregion Step 8 - Append OoXml drawing objects to OoXml run object Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 8 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); double abl = _chemistryModel.MeanBondLength; Debug.WriteLine("Elapsed time for GenerateRun " + swr.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); _telemetry.Write(module, "Timing", $"Rendering {_chemistryModel.Molecules.Count} molecules with {_chemistryModel.AllAtoms.Count} atoms and {_chemistryModel.AllBonds.Count} bonds took {swr.ElapsedMilliseconds.ToString("##,##0")} ms; Average Bond Length: {abl.ToString("#0.00")}"); ShutDownProgress(pb); return(run); }