using jchem with jython

ChemAxon a3d59b832c

26-07-2004 08:25:13

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. (See http://www.jython.org/)








This wrapper code was kindly contributed by Daniel McShan at UCHSC:





Code:



import sys





sys.path.append("/Users/dan/jchem/lib/jchem.jar")





from chemaxon.util import MolHandler


from chemaxon.sss.search import StandardizedMolSearch


...





def subgraph (A, B):


    "Is A a subgraph of B?"


    s = StandardizedMolSearch()


    Amol = MolHandler(A).getMolecule()


    Bmol = MolHandler(B).getMolecule()


    s.setQuery(Amol)


    s.setTarget(Bmol)


    return s.isMatching()


ChemAxon a3d59b832c

25-11-2008 08:46:39

Here is a full jython script that is guaranteed to work:





Code:
#!C:\Programs\jython2.2.1\jython.bat





import sys


sys.path.append("C:\Program Files\ChemAxon\JChem\lib\jchem.jar")


from chemaxon.util import MolHandler


from chemaxon.sss.search import StandardizedMolSearch





def subgraph (A, B):


     "Is A a subgraph of B?"


     s = StandardizedMolSearch()


     Amol = MolHandler(A).getMolecule()


     Bmol = MolHandler(B).getMolecule()


     s.setQuery(Amol)


     s.setTarget(Bmol)


     return s.isMatching()





def search_and_print( Q, T):


   if subgraph(Q,T):


      result = "  found"


   else:


      result = "  not found"


   print "Q:" + Q + " T:" + T + result





search_and_print("CCC", "CCCC")


search_and_print("CCC", "CC")


search_and_print("CCC", "C1CCCCCC1")


search_and_print("C[$(CCO)]", "C1CCCCCC1O")


search_and_print("C[$(CCN)]", "C1CCCCCC1O")


search_and_print("c1ccccc1", "C1=CC=CC=C1")








This is how it can be run, for example:
Quote:
$ C:\Programs\jython2.2.1\jython.bat test_search.jy


Q:CCC T:CCCC found


Q:CCC T:CC not found


Q:CCC T:C1CCCCCC1 found


Q:C[$(CCO)] T:C1CCCCCC1O found


Q:C[$(CCN)] T:C1CCCCCC1O not found


Q:c1ccccc1 T:C1=CC=CC=C1 found