Program TouchMol for Excel using VBA

TouchMol for Excel offers a series of APIs for users to program TouchMol.  With those APIs, users can:

  1. Do name-to-structure conversion
  2. Manifulate structures in cells
  3. Load large compound library, and perform structure search before loading into Excel
  4. Control and customize Compound Profile
  5. Batch compute compound properties
  6. ... many more
TouchMol for Excel VBA APIs
  1. Object TouchMol4Excel2010/2007
    1. bool ImportFile(string position, string filename)
    2. bool ExportFile(string position1, string position2, string filename)
    3. bool InsertStructure(string position, string structure)
    4. bool RemoveStructures(string position1, string position2)
    5. bool ConvertNameToStructure(string position1, string position2)
    6. bool Cleanup(string position1, string position2)
    7. bool RemoveHydrogens(string position1, string position2)
    8. bool Kekulize(string position1, string position2)
    9. bool Aromatize(string position1, string position2)
    10. bool CleanLayouts(string position1, string position2, bool forcerecreate)
    11. bool ShowCompoundProfile(bool f)
    12. string GetStructureName(string position, string language)
    13. string GetMolProperty(string position, string property)
    14. string GetMol(string position, string format)
    15. Molecule GetMol2(string position)
    16. string Version()
    17. CompoundList LoadCompoundList(string file)
    18. Molecule ShowEditor(object input, string oklabel)
    19. Molecule LoadMolFromFile(string file)
    20. Molecule LoadMolFromString(string input)
    21. Molecule LoadMolFromName(string name)
    22. bool CopyStructure()
    23. bool CutStructure()
    24. bool PasteStructure()
    25. bool DoCommand(string cmd)
      cmd: insertname,insertstructure,insertfile,structuresearch,resetsearch,cleanlayout,
      copy,cut,paste,copytable,importsdf,importdatabase,exportsdf,delstructure,compoundprofile,
      showhidestructure,importpubchemassay,importpubchempatent,importpubmet,
      removehydrogens,cleanup,kekulize,calculator
    26. bool CloseTouchMolTable()
  2. Object CompoundList
    1. int GetCount()
    2. CompoundRecord GetRecord(int index)
    3. bool RemoveRecords(int start, int count)
    4. CompoundList Search(string smiles, string searchtype, float cutoff, int maxhits)
    5. bool InsertIntoSheet(string position)
    6. bool InsertIntoSheetSilently(string position)
    7. bool Merge(CompoundList list)
    8. bool Save(string path, string password)
    9. CompoundList FindDuplicates()
  3. Object CompoundRecord
    1. string GetSmiles()
    2. string GetMolfile()
    3. Molecule GetMol()
    4. string GetItem(string key)
    5. bool SetItem(string key, object value)
  4. Object Molecule
    1. string Smiles()
    2. string Molfile()
    3. string InChI()
    4. string InChIKey()
    5. string HashCode() - MolEngine hash code
    6. string MF()
    7. string MolName()
    8. string ToString(string format)
    9. string IUPACName() - Structure-to-name module required
    10. double MW()
    11. double ExactMass()
    12. double XLogP()
    13. int NoRB() - number of rotatable bonds
    14. int NoHD() - number of hydrogen donors
    15. int NoHA() - number of hydrogen acceptors
    16. int CountRings(int size)
    17. int CountAtoms(string symbol)
    18. bool Kekulize()
    19. bool Aromatize()
    20. int RemoveHydrogens()
    21. bool Cleanup() - generate 2D coordinates

Example to Call TouchMol for Excel using VBA:

Sub CallTouchMol()
    ' create TouchMol Addin object
    Dim addIn As COMAddIn
    Set addIn = Application.COMAddIns("TouchMol4Excel2010") ' or "TouchMol4Excel2007"
    Dim t4o As Object
    Set t4o = addIn.Object
    
    ' insert a structure in cell A1
    t4o.InsertStructure "A1", "Diovan"
    t4o.InsertStructure "A2", "C1=CC=CC=C1"
 
    ' name-to-structure
    Range("A4") = "Asprin"
    Range("A5") = "Benadryl"
    Range("A6") = "Lipitor"
    t4o.ConvertNameToStructure "A4", "A6"
 
    ' structure-to-name
    Range("B1").value = t4o.GetStructureName("A1", Nothing)
    Range("B2").value = t4o.GetStructureName("A2", Nothing)
    Range("B4").value = t4o.GetStructureName("A4", Nothing)
    Range("B5").value = t4o.GetStructureName("A5", Nothing)
    Range("B6").value = t4o.GetStructureName("A6", Nothing)
 
    ' compute properties
    Range("C1").value = t4o.GetMolProperty("A1", "Mol_Weight")
    Range("C2").value = t4o.GetMolProperty("A2", "Mol_Weight")
    Range("C4").value = t4o.GetMolProperty("A4", "Mol_Weight")
    Range("C5").value = t4o.GetMolProperty("A5", "Mol_Weight")
    Range("C6").value = t4o.GetMolProperty("A6", "Mol_Weight")
 
    ' kekulize/aromatize
    t4o.Aromatize "A1", "A6"

    ' get smiles
    Range("D1").value = t4o.GetMol("A1", "smiles")
    Range("D2").value = t4o.GetMol("A2", "smiles")
    Range("D4").value = t4o.GetMol("A4", "smiles")
    Range("D5").value = t4o.GetMol("A5", "smiles")
    Range("D6").value = t4o.GetMol("A6", "smiles")



    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Perform fast structure search

    ' create TouchMol object
    Dim addIn As COMAddIn
    Set addIn = Application.COMAddIns("TouchMol4Excel2010") ' or "TouchMol4Excel2007"
    Dim t4o As Object
    Set t4o = addIn.Object

    ' load SDF/CSV/MolEngine compound library in to CompountList object
    Set ms = t4o.LoadCompoundList("c:\temp\test01.molengine")
    MsgBox "total records: " & ms.getcount()
    
    ' do a structure search: substructure, fullstructure, exactfullstructure, similarity
    Set hits = ms.Search("c1ccncc1", "substructure", 0, 0)
    MsgBox "Hits: " & hits.getcount()
    
    ' insert hit records into Excel sheet
    hits.InsertIntoSheet "A1"



   '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   ' Merge, manifulate, and export compound lists
   
   ' create TouchMol object
    Dim addIn As COMAddIn
    Set addIn = Application.COMAddIns("TouchMol4Excel2010") ' or "TouchMol4Excel2007"
    Dim t4o As Object
    Set t4o = addIn.Object
    
   ' merge list
    Set ms1 = t4o.LoadCompoundList("c:\temp\1.sdf")
    Set ms2 = t4o.LoadCompoundList("c:\temp\test01.molengine")
    ms1.Merge ms2

    ' remove the two records starting from the first one
    ms1.Remove 0, 2

    ' modify molecule problem
    ms1.GetRecord(0).SetItem "CAS", "1292-20-1"

    ' save mserged list
    ms1.save "c:\temp\out.sdf", Nothing

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Customize Compound Profile
Public Sub CustomProfiler(m, props)
    props.Add "General", "MF", m.MF
    props.Add "General", "MW", m.MW

    props.Add "Misc", "Creator", “Scilligence”
End Sub

Example Excel Files:

  1. An example to perform fast structure search, the load the hits into excel
  2. Custom Compound Profile