Skip to content

Commit

Permalink
Merged PR 383: Chem4Word 2020 - Release 1 (V3.1.11)
Browse files Browse the repository at this point in the history
* Set Transport Layer Security TLS 1.2 protocol to prevent https errors
* Improved code handling updating of Content Control(s)
* #70 - Improved look of Exterior Double Bond in ACME
* Library now refreshes properly after add / remove; No longer any need to close and open MS Word
* Isotope Labels now clear on change of element
* Improvements to double bond handling in ACME
* Added telemetry to ACME

Related work items: #736, #751, #752, #755
  • Loading branch information
MikeWilliams-UK committed Sep 2, 2020
1 parent dbc5c3f commit bfd7ea4
Show file tree
Hide file tree
Showing 39 changed files with 254 additions and 279 deletions.
Binary file modified docs/Chem4Word-Version3-1-User-Manual.docx
Binary file not shown.
6 changes: 3 additions & 3 deletions src/Chem4Word.V3/Data/Chem4Word-Versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<Version>
<Number>3.1.11 Release 1</Number>
<IsBeta>false</IsBeta>
<Released>19-Aug-2020</Released>
<Released>02-Sep-2020</Released>
<Changes>
<Change>Improved code handling updating of Content Control(s)</Change>
<Change>https://github.com/Chem4Word/Version3-1/issues/70 - Improved look of Exterior Double Bond in ACME</Change>
<Change>Library now refreshes properly after add / remove without closing word</Change>
<Change>Isotope Labels clear on change of element</Change>
<Change>Library now refreshes properly after add / remove; No longer any need to close and open MS Word</Change>
<Change>Isotope Labels now clear on change of element</Change>
<Change>Improvements to double bond handling in ACME</Change>
<Change>Added telemetry to ACME</Change>
</Changes>
Expand Down
2 changes: 1 addition & 1 deletion src/Chem4Word.V3/Data/This-Version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<Version>
<Number>3.1.11 Release 1</Number>
<IsBeta>false</IsBeta>
<Released>19-Aug-2020</Released>
<Released>02-Sep-2020</Released>
</Version>
8 changes: 4 additions & 4 deletions src/Chem4Word.V3/Helpers/UpdateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,15 @@ private static string GetVersionsXmlFile()
string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

string VersionsFile = $"{Constants.Chem4WordVersionFiles}/Chem4Word-Versions.xml";
#if DEBUG
//VersionsFile = $"{Constants.Chem4WordVersionFiles}/Chem4Word-Versions-Debug.xml";
#endif

string PrimaryDomain = "https://www.chem4word.co.uk";
string[] Domains = { "https://www.chem4word.co.uk", "http://www.chem4word.com", "https://chem4word.azurewebsites.net" };
string VersionsFileMarker = "<Id>f3c4f4db-2fff-46db-b14a-feb8e09f7742</Id>";

string contents = null;

var securityProtocol = ServicePointManager.SecurityProtocol;
ServicePointManager.SecurityProtocol = securityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

bool foundOurXmlFile = false;
foreach (var domain in Domains)
{
Expand Down Expand Up @@ -384,6 +383,7 @@ private static string GetVersionsXmlFile()
}
}

ServicePointManager.SecurityProtocol = securityProtocol;
return contents;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.11.7536")]
[assembly: AssemblyFileVersion("3.1.11.7536")]
[assembly: AssemblyVersion("3.1.11.7550")]
[assembly: AssemblyFileVersion("3.1.11.7550")]
8 changes: 8 additions & 0 deletions src/Chem4Word.V3/WebServices/ChemicalServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public ChemicalServicesResult GetChemicalServicesResult(string molfile)
DateTime started = DateTime.Now;

ChemicalServicesResult data = null;
var securityProtocol = ServicePointManager.SecurityProtocol;

try
{
ServicePointManager.SecurityProtocol = securityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

using (HttpClient httpClient = new HttpClient())
{
var formData = new List<KeyValuePair<string, string>>();
Expand Down Expand Up @@ -84,6 +87,7 @@ public ChemicalServicesResult GetChemicalServicesResult(string molfile)
{
Telemetry.Write(module, "Timing", string.Join(Environment.NewLine, data.Messages));
}

if (data.Errors.Any())
{
Telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, data.Errors));
Expand All @@ -103,6 +107,10 @@ public ChemicalServicesResult GetChemicalServicesResult(string molfile)
Telemetry.Write(module, "Exception", e1.Message);
Telemetry.Write(module, "Exception", e1.ToString());
}
finally
{
ServicePointManager.SecurityProtocol = securityProtocol;
}

DateTime ended = DateTime.Now;
TimeSpan duration = ended - started;
Expand Down
12 changes: 12 additions & 0 deletions src/Chem4WordTests/Chem4WordTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@
<ItemGroup>
<EmbeddedResource Include="Resources\CML\NestedParafuchsinCarbol.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\CML\Trimethylamine-Normal.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\CML\Trimethylamine-MinusNamespace.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\CML\Trimethylamine-MinusArrays.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\CML\Trimethylamine-MoleculeRoot.xml" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
167 changes: 35 additions & 132 deletions src/Chem4WordTests/Persistence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,143 +15,51 @@ namespace Chem4WordTests
{
public class Persistence
{
[Fact]
public void CmlImportNoAtoms()
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("NoAtoms.xml"));

// Basic sanity checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 0, $"Expected 0 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 0, $"Expected 0 Bonds; Got {m.TotalBondsCount}");

// Check that names and formulae have not been trashed
Assert.True(m.Molecules.Values.First().Names.Count == 1, $"Expected 1 Chemical Names; Got {m.Molecules.Values.First().Names.Count}");
}

[Fact]
public void CmlImportBenzene()
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("Benzene.xml"));

// Basic sanity checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 6, $"Expected 6 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 6, $"Expected 6 Bonds; Got {m.TotalBondsCount}");

// Check that names and formulae have not been trashed
Assert.True(m.Molecules.Values.First().Names.Count == 3, $"Expected 3 Chemical Names; Got {m.Molecules.Values.First().Names.Count}");
Assert.True(m.Molecules.Values.First().Formulas.Count == 2, $"Expected 2 Formulae; Got {m.Molecules.Values.First().Formulas.Count }");

// Check that we have one ring
Assert.True(m.Molecules.Values.First().Rings.Count == 1, $"Expected 1 Ring; Got {m.Molecules.Values.First().Rings.Count}");
}

[Fact]
public void CmlImportTestosterone()
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("Testosterone.xml"));

// Basic Sanity Checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 25, $"Expected 25 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 28, $"Expected 28 Bonds; Got {m.TotalBondsCount}");

// Check that names and formulae have not been trashed
Assert.True(m.Molecules.Values.First().Names.Count == 4, $"Expected 4 Chemical Names; Got {m.Molecules.Values.First().Names.Count}");
Assert.True(m.Molecules.Values.First().Formulas.Count == 2, $"Expected 2 Formulae; Got {m.Molecules.Values.First().Formulas.Count }");

Assert.True(m.Molecules.Values.First().Rings.Count == 4, $"Expected 4 Rings; Got {m.Molecules.Values.First().Rings.Count}");

var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 4, $"Expected 4 Rings; Got {list.Count}");
}

[Fact]
public void CmlImportTestosteroneThenRefresh()
[Theory]
[InlineData("Trimethylamine-Normal.xml")]
[InlineData("Trimethylamine-MinusArrays.xml")]
[InlineData("Trimethylamine-MinusNamespace.xml")]
[InlineData("Trimethylamine-MoleculeRoot.xml")]
public void CheckCmlImportVariants(string file)
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("Testosterone.xml"));

// Basic Sanity Checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 25, $"Expected 25 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 28, $"Expected 28 Bonds; Got {m.TotalBondsCount}");

// Check that names and formulae have not been trashed
Assert.True(m.Molecules.Values.First().Names.Count == 4, $"Expected 4 Chemical Names; Got {m.Molecules.Values.First().Names.Count}");
Assert.True(m.Molecules.Values.First().Formulas.Count == 2, $"Expected 2 Formulae; Got {m.Molecules.Values.First().Formulas.Count }");
// Arrange

Assert.True(m.Molecules.Values.First().Rings.Count == 4, $"Expected 4 Rings; Got {m.Molecules.Values.First().Rings.Count}");
var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 4, $"Expected 4 Rings; Got {list.Count}");
}

[Fact]
public void CmlImportCopperPhthalocyanine()
{
// Act
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("CopperPhthalocyanine.xml"));
Model m = mc.Import(ResourceHelper.GetStringResource(file));

// Basic Sanity Checks
// Assert
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 57, $"Expected 57 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 68, $"Expected 68 Bonds; Got {m.TotalBondsCount}");
var molecule = m.Molecules.Values.First();
Assert.True(molecule.Atoms.Count == 4, $"Expected 4 Atoms; Got {molecule.Atoms.Count}");
Assert.True(molecule.Bonds.Count == 3, $"Expected 3 Bonds; Got {molecule.Bonds.Count}");

Assert.True(m.Molecules.Values.First().Rings.Count == 12, $"Expected 12 Rings; Got {m.Molecules.Values.First().Rings.Count}");
var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 12, $"Expected 12 Rings; Got {list.Count}");
var atom = molecule.Atoms.Values.ToArray()[1];
Assert.True(atom.SymbolText == "N", $"Expected N; Got {atom.SymbolText}");
}

[Fact]
public void CmlImportCopperPhthalocyanineThenRefresh()
[Theory]
[InlineData("NoAtoms.xml", 1, 0, 0, 0, 0, 1, 0)]
[InlineData("Benzene.xml", 1, 6, 6, 1, 1, 3, 2)]
[InlineData("Testosterone.xml", 1, 25, 28, 4, 4, 4, 2)]
[InlineData("Phthalocyanine.xml", 1, 58, 66, 9, 8, 2, 3)]
[InlineData("CopperPhthalocyanine.xml", 1, 57, 68, 12, 12, 1, 0)]
public void CmlImport(string file, int molecules, int atoms, int bonds, int allRings, int placementRings, int names, int formulas)
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("CopperPhthalocyanine.xml"));
Model model = mc.Import(ResourceHelper.GetStringResource(file));

// Basic Sanity Checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 57, $"Expected 57 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 68, $"Expected 68 Bonds; Got {m.TotalBondsCount}");
Assert.True(model.Molecules.Count == molecules, $"Expected {molecules} Molecules; Got {model.Molecules.Count}");
Assert.True(model.TotalAtomsCount == atoms, $"Expected {atoms} Atoms; Got {model.TotalAtomsCount}");
Assert.True(model.TotalBondsCount == bonds, $"Expected {bonds} Bonds; Got {model.TotalBondsCount}");

Assert.True(m.Molecules.Values.First().Rings.Count == 12, $"Expected 12 Rings; Got {m.Molecules.Values.First().Rings.Count}");
var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 12, $"Expected 12 Rings; Got {list.Count}");
}

[Fact]
public void CmlImportPhthalocyanine()
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("Phthalocyanine.xml"));

// Basic Sanity Checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 58, $"Expected 58 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 66, $"Expected 66 Bonds; Got {m.TotalBondsCount}");

Assert.True(m.Molecules.Values.First().Rings.Count == 9, $"Expected 9 Rings; Got {m.Molecules.Values.First().Rings.Count}");
var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 8, $"Expected 8 Rings; Got {list.Count}");
}

[Fact]
public void CmlImportPhthalocyanineThenRefresh()
{
CMLConverter mc = new CMLConverter();
Model m = mc.Import(ResourceHelper.GetStringResource("Phthalocyanine.xml"));

// Basic Sanity Checks
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 58, $"Expected 58 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 66, $"Expected 66 Bonds; Got {m.TotalBondsCount}");
Molecule molecule = model.Molecules.Values.First();
Assert.True(molecule.Rings.Count == allRings, $"Expected {allRings} Rings; Got {molecule.Rings.Count}");
Assert.True(molecule.Names.Count == names, $"Expected {names} Chemical Names; Got {molecule.Names.Count}");
Assert.True(molecule.Formulas.Count == formulas, $"Expected {formulas} Chemical Formulas; Got {molecule.Formulas.Count}");

Assert.True(m.Molecules.Values.First().Rings.Count == 9, $"Expected 9 Rings; Got {m.Molecules.Values.First().Rings.Count}");
var list = m.Molecules.Values.First().SortRingsForDBPlacement();
Assert.True(list.Count == 8, $"Expected 8 Rings; Got {list.Count}");
var list = molecule.SortRingsForDBPlacement();
Assert.True(list.Count == placementRings, $"Expected {placementRings} Placement Rings; Got {list.Count}");
}

[Fact]
Expand Down Expand Up @@ -228,6 +136,7 @@ public void CmlImportExportNested()
Assert.True(molecule_2.Atoms.Count == 6, $"Expected 6 Atoms; Got {molecule_2.Atoms.Count}");
}

// SDFile and MOLFile import
[Fact]
public void SdfImportBenzene()
{
Expand Down Expand Up @@ -257,19 +166,13 @@ public void SdfImportBasicParafuchsin()
Assert.True(m.Molecules.Count == 1, $"Expected 1 Molecule; Got {m.Molecules.Count}");

var mol = m.Molecules.Values.First();
Assert.True(mol.Molecules.Count == 2,
$"Expected 2 Child Molecules; Got {mol.Molecules.Count}");
Assert.True(mol.Molecules.Count == 2, $"Expected 2 Child Molecules; Got {mol.Molecules.Count}");
Assert.True(m.TotalAtomsCount == 41, $"Expected 41 Atoms; Got {m.TotalAtomsCount}");
Assert.True(m.TotalBondsCount == 42, $"Expected 42 Bonds; Got {m.TotalBondsCount}");

// Check that we got three rings
var mol2 = mol.Molecules.Values.Skip(1).First();
Assert.True(mol2.Rings.Count == 3,
$"Expected 3 Rings; Got {mol2.Rings.Count}");

string molstring = mc.Export(m);
mc = new SdFileConverter();
Model m2 = mc.Import(molstring);
Assert.True(mol2.Rings.Count == 3, $"Expected 3 Rings; Got {mol2.Rings.Count}");
}
}
}
4 changes: 2 additions & 2 deletions src/Chem4WordTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.11.7536")]
[assembly: AssemblyFileVersion("3.1.11.7536")]
[assembly: AssemblyVersion("3.1.11.7550")]
[assembly: AssemblyFileVersion("3.1.11.7550")]
13 changes: 13 additions & 0 deletions src/Chem4WordTests/Resources/CML/Trimethylamine-MinusArrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<cml:cml xmlns:conventions="http://www.xml-cml.org/convention/" xmlns:cml="http://www.xml-cml.org/schema" xmlns:cmlDict="http://www.xml-cml.org/dictionary/cml/" xmlns:nameDict="http://www.xml-cml.org/dictionary/cml/name/" xmlns:c4w="http://www.chem4word.com/cml" conventions="convention:molecular">
<cml:molecule id="m1">
<cml:formula id="m1.f0" concise="C 3 H 9 N 1" />
<cml:atom id="a1" elementType="C" x2="482.679492" y2="390.0" />
<cml:atom id="a2" elementType="N" x2="500.0" y2="380.0" />
<cml:atom id="a3" elementType="C" x2="517.320508" y2="390.0" />
<cml:atom id="a4" elementType="C" x2="500.0" y2="360.0" />
<cml:bond id="b1" atomRefs2="a1 a2" order="S" />
<cml:bond id="b2" atomRefs2="a2 a3" order="S" />
<cml:bond id="b3" atomRefs2="a2 a4" order="S" />
</cml:molecule>
</cml:cml>
17 changes: 17 additions & 0 deletions src/Chem4WordTests/Resources/CML/Trimethylamine-MinusNamespace.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<cml xmlns:conventions="http://www.xml-cml.org/convention/" xmlns:cml="http://www.xml-cml.org/schema" xmlns:cmlDict="http://www.xml-cml.org/dictionary/cml/" xmlns:nameDict="http://www.xml-cml.org/dictionary/cml/name/" xmlns:c4w="http://www.chem4word.com/cml" conventions="convention:molecular">
<molecule id="m1">
<formula id="m1.f0" concise="C 3 H 9 N 1" />
<atomArray>
<atom id="a1" elementType="C" x2="482.679492" y2="390.0" />
<atom id="a2" elementType="N" x2="500.0" y2="380.0" />
<atom id="a3" elementType="C" x2="517.320508" y2="390.0" />
<atom id="a4" elementType="C" x2="500.0" y2="360.0" />
</atomArray>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="S" />
<bond id="b2" atomRefs2="a2 a3" order="S" />
<bond id="b3" atomRefs2="a2 a4" order="S" />
</bondArray>
</molecule>
</cml>
15 changes: 15 additions & 0 deletions src/Chem4WordTests/Resources/CML/Trimethylamine-MoleculeRoot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<molecule id="m1" xmlns:cml="http://www.xml-cml.org/schema">
<formula id="m1.f0" concise="C 3 H 9 N 1" />
<atomArray>
<atom id="a1" elementType="C" x2="482.679492" y2="390.0" />
<atom id="a2" elementType="N" x2="500.0" y2="380.0" />
<atom id="a3" elementType="C" x2="517.320508" y2="390.0" />
<atom id="a4" elementType="C" x2="500.0" y2="360.0" />
</atomArray>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="S" />
<bond id="b2" atomRefs2="a2 a3" order="S" />
<bond id="b3" atomRefs2="a2 a4" order="S" />
</bondArray>
</molecule>
17 changes: 17 additions & 0 deletions src/Chem4WordTests/Resources/CML/Trimethylamine-Normal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<cml:cml xmlns:conventions="http://www.xml-cml.org/convention/" xmlns:cml="http://www.xml-cml.org/schema" xmlns:cmlDict="http://www.xml-cml.org/dictionary/cml/" xmlns:nameDict="http://www.xml-cml.org/dictionary/cml/name/" xmlns:c4w="http://www.chem4word.com/cml" conventions="convention:molecular">
<cml:molecule id="m1">
<cml:formula id="m1.f0" concise="C 3 H 9 N 1" />
<cml:atomArray>
<cml:atom id="a1" elementType="C" x2="482.679492" y2="390.0" />
<cml:atom id="a2" elementType="N" x2="500.0" y2="380.0" />
<cml:atom id="a3" elementType="C" x2="517.320508" y2="390.0" />
<cml:atom id="a4" elementType="C" x2="500.0" y2="360.0" />
</cml:atomArray>
<cml:bondArray>
<cml:bond id="b1" atomRefs2="a1 a2" order="S" />
<cml:bond id="b2" atomRefs2="a2 a3" order="S" />
<cml:bond id="b3" atomRefs2="a2 a4" order="S" />
</cml:bondArray>
</cml:molecule>
</cml:cml>
Loading

0 comments on commit bfd7ea4

Please sign in to comment.