/// <summary> /// Convert from one format to another /// </summary> /// <param name="newFormat"></param> /// <returns></returns> public MoleculeMx ConvertTo( MoleculeFormat molFormatType) { string molString, msg; bool conversionFailed = false; MoleculeMx mol = new MoleculeMx(molFormatType); try { // If no change in type, just copy value if (this.PrimaryFormat == molFormatType) // any change in type? { molString = this.PrimaryValue; } else { molString = GetMoleculeString(molFormatType); // convert from old type if possible } mol.SetPrimaryTypeAndValue(molFormatType, molString); return(mol); } catch (Exception ex) // handle structures that don't convert - issue #216 { //DebugLog.Message("ChemicalStructure.Convert exception for structure: \r\n" + Value + "\r\n" + // DebugLog.FormatExceptionMessage(ex)); //throw new Exception(ex.Message, ex); return(new MoleculeMx(PrimaryFormat, "")); // return blank structure } }
public static void SetMoleculeToTestHelmString( string cid, MoleculeMx mol) { if (!Lex.IsInteger(cid)) { return; } int i1 = int.Parse(cid); if (i1 > 0 && i1 < 10) { string helm = GetTestHelmString(i1); mol.SetPrimaryTypeAndValue(MoleculeFormat.Helm, helm); } }
/// <summary> /// Convert any ChemicalStructures containing a sketch value to a ChimeString for proper serialization /// </summary> /// <param name="oa"></param> public static void ConvertMoleculesToChimeStrings(object[] oa) { for (int ci = 0; ci < oa.Length; ci++) { if (!(oa[ci] is MoleculeMx)) { continue; } MoleculeMx cs = oa[ci] as MoleculeMx; if (Math.Abs(1) == 1) { continue; // noop for now } //if (cs.Type != StructureFormat.Sketch) continue; // obsolete MoleculeFormat type = MoleculeFormat.Chime; string value = cs.GetChimeString(); cs.SetPrimaryTypeAndValue(type, value); } }