private void SetupCustomizers() { if (customizers == null) { customizers = new Dictionary <string, ICMLCustomizer>(); } try { Debug.WriteLine("Starting loading Customizers..."); var reader = new StreamReader(ResourceLoader.GetAsStream(this.GetType(), CUSTOMIZERS_LIST)); int customizerCount = 0; string customizerName; while ((customizerName = reader.ReadLine()) != null) { // load them one by one customizerCount++; if (customizers.ContainsKey(customizerName)) { try { ICMLCustomizer customizer = (ICMLCustomizer)this.GetType().Assembly.CreateInstance(customizerName); if (customizer == null) { Trace.TraceInformation("Could not find this Customizer: ", customizerName); } else { customizers[customizer.GetType().FullName] = customizer; Trace.TraceInformation("Loaded Customizer: ", customizer.GetType().Name); } } catch (IOException exception) { Trace.TraceWarning("Could not load this Customizer: ", customizerName); Trace.TraceWarning(exception.Message); Debug.WriteLine(exception); } catch (Exception exception) { Trace.TraceWarning(exception.Message); Debug.WriteLine(exception); } } else { Trace.TraceWarning("Duplicate attempt to register a customizer"); } } Trace.TraceInformation("Number of loaded customizers: ", customizerCount); } catch (Exception exception) { Trace.TraceError($"Could not load this list: {CUSTOMIZERS_LIST}"); Debug.WriteLine(exception); } }
public void RegisterCustomizer(ICMLCustomizer customizer) { if (customizers == null) { customizers = new List <ICMLCustomizer>(); } customizers.Add(customizer); Trace.TraceInformation("Loaded Customizer: ", customizer.GetType().Name); }
public void RegisterCustomizer(ICMLCustomizer customizer) { if (customizers == null) { customizers = new Dictionary <string, ICMLCustomizer>(); } if (!customizers.ContainsKey(customizer.GetType().Name)) { customizers[customizer.GetType().Name] = customizer; Trace.TraceInformation("Loaded Customizer: ", customizer.GetType().Name); } else { Trace.TraceWarning("Duplicate attempt to register a customizer"); } }
public CMLBond CDKJBondToCMLBond(IBond cdkBond) { CMLBond cmlBond = new CMLBond(); this.CheckPrefix(cmlBond); if (string.IsNullOrEmpty(cdkBond.Id)) { cmlBond.Id = "b" + cdkBond.GetHashCode(); } else { cmlBond.Id = cdkBond.Id; } string[] atomRefArray = new string[cdkBond.Atoms.Count]; for (int i = 0; i < cdkBond.Atoms.Count; i++) { string atomID = cdkBond.Atoms[i].Id; if (string.IsNullOrEmpty(atomID)) { atomRefArray[i] = "a" + cdkBond.Atoms[i].GetHashCode().ToString(NumberFormatInfo.InvariantInfo); } else { atomRefArray[i] = atomID; } } if (atomRefArray.Length == 2) { cmlBond.AtomRefs2 = atomRefArray; } else { cmlBond.AtomRefs = atomRefArray; } BondOrder border = cdkBond.Order; switch (border) { case BondOrder.Single: cmlBond.Order = "S"; break; case BondOrder.Double: cmlBond.Order = "D"; break; case BondOrder.Triple: cmlBond.Order = "T"; break; default: CMLScalar scalar = new CMLScalar(); this.CheckPrefix(scalar); scalar.DictRef = "cdk:bondOrder"; scalar.Title = "order"; scalar.SetValue(cdkBond.Order.Numeric()); cmlBond.Add(scalar); break; } if (cdkBond.IsAromatic) { CMLBondType bType = new CMLBondType { DictRef = "cdk:aromaticBond" }; cmlBond.Add(bType); } switch (cdkBond.Stereo) { case BondStereo.Up: case BondStereo.Down: CMLBondStereo bondStereo = new CMLBondStereo(); this.CheckPrefix(bondStereo); if (cdkBond.Stereo == BondStereo.Up) { bondStereo.DictRef = "cml:W"; bondStereo.Value = "W"; } else { bondStereo.DictRef = "cml:H"; bondStereo.Value = "H"; } cmlBond.Add(bondStereo); break; } if (cdkBond.GetProperties().Count > 0) { WriteProperties(cdkBond, cmlBond); } foreach (var element in customizers.Keys) { ICMLCustomizer customizer = customizers[element]; try { customizer.Customize(cdkBond, cmlBond); } catch (Exception exception) { Trace.TraceError("Error while customizing CML output with customizer: ", customizer.GetType().Name); Debug.WriteLine(exception); } } return(cmlBond); }
public CMLAtom CDKAtomToCMLAtom(IAtomContainer container, IAtom cdkAtom) { CMLAtom cmlAtom = new CMLAtom(); this.CheckPrefix(cmlAtom); AddAtomID(cdkAtom, cmlAtom); AddDictRef(cdkAtom, cmlAtom); cmlAtom.ElementType = cdkAtom.Symbol; if (cdkAtom is IPseudoAtom) { string label = ((IPseudoAtom)cdkAtom).Label; if (label != null) { cmlAtom.Title = label; } cmlAtom.ElementType = "Du"; } Map2DCoordsToCML(cmlAtom, cdkAtom); Map3DCoordsToCML(cmlAtom, cdkAtom); MapFractionalCoordsToCML(cmlAtom, cdkAtom); int?formalCharge = cdkAtom.FormalCharge; if (formalCharge != null) { cmlAtom.FormalCharge = formalCharge.Value; } // CML's hydrogen count consists of the sum of implicit and explicit // hydrogens (see bug #1655045). int?totalHydrogen = cdkAtom.ImplicitHydrogenCount; if (totalHydrogen != null) { if (container != null) { foreach (var bond in container.GetConnectedBonds(cdkAtom)) { foreach (var atom in bond.Atoms) { if (AtomicNumbers.H.Equals(atom.AtomicNumber) && atom != cdkAtom) { totalHydrogen++; } } } } // else: it is the implicit hydrogen count cmlAtom.HydrogenCount = totalHydrogen.Value; } // else: don't report it, people can count the explicit Hs themselves int?massNumber = cdkAtom.MassNumber; if (!(cdkAtom is IPseudoAtom)) { if (massNumber != null) { cmlAtom.IsotopeNumber = massNumber.Value; } } if (cdkAtom.Charge != null) { CMLScalar scalar = new CMLScalar(); this.CheckPrefix(scalar); scalar.DictRef = "cdk:partialCharge"; scalar.SetValue(cdkAtom.Charge.Value); cmlAtom.Add(scalar); } WriteProperties(cdkAtom, cmlAtom); if (cdkAtom.IsAromatic) { CMLScalar aromAtom = new CMLScalar { DictRef = "cdk:aromaticAtom" }; cmlAtom.Add(aromAtom); } foreach (var element in customizers.Keys) { ICMLCustomizer customizer = customizers[element]; try { customizer.Customize(cdkAtom, cmlAtom); } catch (Exception exception) { Trace.TraceError("Error while customizing CML output with customizer: ", customizer.GetType().Name); Debug.WriteLine(exception); } } return(cmlAtom); }