Symyx-Accelrys

Integrating Web Services with the Symyx/Accelrys Drawing Program

 * Researcher: James Jack**
 * Licence: CC0**

**Installing a Web Service Add-In: Melting Point Example**
1. If you do not already have the Symyx/Accelrys drawing program, download and install the freeware Accelrys Draw - No Fee

2. Download and unzip the [|melting point add-in]. To install simply copy to the relative location shown: Note: The following path was used for the free version on windows XP: "C:\Program Files\Symyx\Symyx Draw 4.0\AddIns"

3. Draw a structure of interest and click the menu as shown:

4. Wait while the melting point lookup runs:

5. The melting point arrives as "hover and drop" text. Move it to a suitable position and click drop.

Sample Code: code public string LookupMeltingPoint(string molfileString, string doPredictedmeltingpoint, string doExperimentalmeltingpoint, string doSMILES, string doCsid, string doCslink) {           // Create the web request var request = WebRequest.Create(Address) as HttpWebRequest; var requestResult = string.Empty;

// Set type to POST if (request != null) {               request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; }

// this code runs in a back ground thread, at various points we test to see if the user has cancelled... if (_bgw.CancellationPending) {               return string.Empty; }

// Create a byte array of the data we want to send var byteData = Encoding.UTF8.GetBytes(String.Format(RequestString, molfileString, doPredictedmeltingpoint, doExperimentalmeltingpoint, doSMILES, doCsid, doCslink));

// Set the content length in the request headers if (request != null) {               request.ContentLength = byteData.Length;

// Write data using (var postStream = request.GetRequestStream) {                   postStream.Write(byteData, 0, byteData.Length); }

// Get response using (var response = request.GetResponse as HttpWebResponse) {                   if (_bgw.CancellationPending) {                       return string.Empty; }                   // Get the response stream else if (response != null) {                       var reader = new StreamReader(response.GetResponseStream);

requestResult = reader.ReadToEnd; }               }            }

if (!String.IsNullOrEmpty(requestResult)) {

var results = GetCDataFromXML(requestResult); requestResult = string.Empty;

foreach (var result in results) {                   if (_bgw.CancellationPending) {                       return string.Empty; }                   else if (!string.IsNullOrEmpty(result)) {                       var properties = GetSDFData(result); var experimentalMeltingPoint = string.Empty; var predictedMeltingPoint = string.Empty;

if (properties.ContainsKey("experimental_mp[C]")) experimentalMeltingPoint = properties["experimental_mp[C]"].Trim;

if (properties.ContainsKey("experimental_mp[C]")) predictedMeltingPoint = properties["predicted_mp[C]"].Trim;

if (!String.IsNullOrEmpty(experimentalMeltingPoint)) requestResult += "Experimental Melting Point: " + experimentalMeltingPoint + "°C";

if (!String.IsNullOrEmpty(predictedMeltingPoint)) requestResult += "Predicted Melting Point: " + predictedMeltingPoint + "°C"; }               }            }

return requestResult; }

private Dictionary GetSDFData(string record) {           var currentSDFData = record.Contains("M  END") ? record.Replace("> <", "|").Replace("> <", "|").Replace(">     <", "|") : record.Replace("> <", "|").Replace(">  <", "|").Replace(">     <", "|"); var properties = new Dictionary; currentSDFData = currentSDFData.Substring(1).Replace("\r", "").Replace("\n", "").Replace("$$$$", ""); //remove the first "|", remove line breaks, remove $$$$ var currentSDFDataArray = currentSDFData.Split(Convert.ToChar("|")); for (var i = 0; i < currentSDFDataArray.Length; i++) {               try {                   var data = currentSDFDataArray[i].Split(Convert.ToChar(">")); if (data[1].Contains("\n")) data[1] = data[1].Substring(data[1].IndexOf("\n")); properties[data[0].Trim] = data[1].Trim; }               catch {

}           }            return properties; }

private List GetCDataFromXML(string xml) {           //initialize output object List result = new List ;

// In case of xml string instead of file path XmlReader reader = XmlReader.Create(new StringReader(xml)); reader.MoveToContent; //navigates only CData elements while (reader.Read) {               switch (reader.NodeType) {                   case XmlNodeType.CDATA: result.Add(reader.Value); break; }           }            //returns collection of CData return result; } code