Esempio n. 1
0
def get_mcs_indices_indigo(m_sdf, t_sdf, timeout=None, exact=False):
    import indigo
    indigo = indigo.Indigo()

    m_mol = indigo.loadMolecule(m_sdf)
    t_mol = indigo.loadMolecule(t_sdf)

    # find common substructure
    arr = indigo.createArray()
    arr.arrayAdd(m_mol)
    arr.arrayAdd(t_mol)
    mcs = indigo.extractCommonScaffold(arr, 'exact' if exact else 'approx')

    # match to scaffold
    query = indigo.loadQueryMolecule(mcs.smiles())
    m_match = indigo.substructureMatcher(m_mol).match(query)
    t_match = indigo.substructureMatcher(t_mol).match(query)

    # atom indices of match
    m_atoms = [m_match.mapAtom(a) for a in query.iterateAtoms()]
    t_atoms = [t_match.mapAtom(a) for a in query.iterateAtoms()]
    m_indices = [a.index() for a in m_atoms if a is not None]
    t_indices = [a.index() for a in t_atoms if a is not None]

    return m_indices, t_indices
Esempio n. 2
0
    def do_GET(self):
        if self.path.endswith("knocknock"):
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write("You are welcome!")
            return
        if self.path.find('?') != -1:
            self.path, self.query_string = \
                self.path.split('?', 1)
        else:
            self.query_string = ''

        self.globals = dict(cgi.parse_qsl(self.query_string))

        if self.path.endswith("layout"):
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            mol = indigo.loadQueryMolecule(self.globals['smiles'])
            mol.layout()
            self.wfile.write("Ok.\n")
            self.wfile.write(mol.molfile())
            return

        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Esempio n. 3
0
def get_mcs_indices_indigo(m_sdf, t_sdf, timeout=None, exact=False):
    import indigo
    indigo = indigo.Indigo()

    m_mol = indigo.loadMolecule(m_sdf)
    t_mol = indigo.loadMolecule(t_sdf)

    # find common substructure
    arr = indigo.createArray()
    arr.arrayAdd(m_mol)
    arr.arrayAdd(t_mol)
    mcs = indigo.extractCommonScaffold(arr, 'exact' if exact else 'approx')

    # match to scaffold
    query = indigo.loadQueryMolecule(mcs.smiles())
    m_match = indigo.substructureMatcher(m_mol).match(query)
    t_match = indigo.substructureMatcher(t_mol).match(query)

    # atom indices of match
    m_atoms = [m_match.mapAtom(a) for a in query.iterateAtoms()]
    t_atoms = [t_match.mapAtom(a) for a in query.iterateAtoms()]
    m_indices = [a.index() for a in m_atoms if a is not None]
    t_indices = [a.index() for a in t_atoms if a is not None]

    return m_indices, t_indices
Esempio n. 4
0
  def do_GET(self):
    if self.path.endswith("knocknock"):
      self.send_response(200)
      self.send_header('Content-type',	'text/plain')
      # Allow CORS and x-json
      self.send_header('Access-Control-Allow-Origin', '*')
      self.send_header('Access-Control-Expose-Headers', 'x-json')
      self.end_headers()
      self.wfile.write("You are welcome!")
      return
    if self.path.find('?') != -1:
      self.path, self.query_string = \
          self.path.split('?', 1)
    else:
      self.query_string = ''
      
    self.globals = dict(cgi.parse_qsl(self.query_string))
      
    if self.path.endswith("layout"):
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      # Allow CORS and x-json
      self.send_header('Access-Control-Allow-Origin', '*')
      self.send_header('Access-Control-Expose-Headers', 'x-json')
      self.end_headers()
      mol = indigo.loadQueryMolecule(self.globals['smiles'])
      mol.layout()
      self.wfile.write("Ok.\n")
      self.wfile.write(mol.molfile())
      return

    SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Esempio n. 5
0
def handle_layout(request):
    if request.method == "GET" and request.GET.has_key("smiles"):
        moldata = request.GET["smiles"]
    elif request.method == "POST" and request.POST.has_key("moldata"):
        moldata = request.POST["moldata"]
    else:
        raise Http404
    mol = indigo.loadQueryMolecule(moldata)
    mol.layout()
    return HttpResponse(content="Ok.\n" + mol.molfile(), mimetype="text/plain")
Esempio n. 6
0
def handle_layout(request):
    if request.method == 'GET' and request.GET.has_key("smiles"):
        moldata = request.GET["smiles"]
    elif request.method == 'POST' and request.POST.has_key("moldata"):
        moldata = request.POST["moldata"]
    else:
        raise Http404
    mol = indigo.loadQueryMolecule(moldata)
    mol.layout()
    return HttpResponse(content="Ok.\n" + mol.molfile(), mimetype='text/plain')
    def do_POST(self):
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
        if ctype == 'multipart/form-data':
            if self.path.endswith("open"):
                query = cgi.parse_multipart(self.rfile, pdict)
                self.send_response(200)
                self.send_header('Content-type', 'text/plain')
                # Allow CORS and x-json
                self.send_header('Access-Control-Allow-Origin', '*')
                self.send_header('Access-Control-Expose-Headers', 'x-json')
                self.end_headers()
                self.wfile.write("Ok.\n")
                self.wfile.write(query['filedata'][0])
                return
            if self.path.endswith("save"):
                query = cgi.parse_multipart(self.rfile, pdict)
                filedata = query['filedata'][0]
                first = filedata.split("\n")[0]
                rest = "\n".join(filedata.split("\n")[1:])

                self.send_response(200)
                if first == "smi":
                    self.send_header('Content-type',
                                     'chemical/x-daylight-smiles')
                elif first == "mol":
                    self.send_header('Content-type', 'chemical/x-mdl-molfile')
                else:
                    self.send_header('Content-type', 'text/plain')

                self.send_header('Content-Disposition',
                                 'attachment; filename=ketcher.' + first)
                # Allow CORS and x-json
                self.send_header('Access-Control-Allow-Origin', '*')
                self.send_header('Access-Control-Expose-Headers', 'x-json')
                self.end_headers()
                self.wfile.write(rest)
            return

        if self.path.endswith("layout"):
            length = int(self.headers['content-length'])
            self.globals = dict(cgi.parse_qsl(self.rfile.read(length)))
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            # Allow CORS and x-json
            self.send_header('Access-Control-Allow-Origin', '*')
            self.send_header('Access-Control-Expose-Headers', 'x-json')
            self.end_headers()
            mol = indigo.loadQueryMolecule(self.globals['moldata'])
            mol.layout()
            self.wfile.write("Ok.\n")
            self.wfile.write(mol.molfile())
            return
Esempio n. 8
0
  def do_GET(self):
    if self.path.endswith("knocknock"):
      self.send_response(200)
      self.send_header('Content-type',  'text/plain')
      self.end_headers()
      self.wfile.write("You are welcome!")
      return
    if self.path.find('?') != -1:
      self.path, self.query_string = \
          self.path.split('?', 1)
    else:
      self.query_string = ''
      
    self.globals = dict(cgi.parse_qsl(self.query_string))
      
    if self.path.endswith("layout"):
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      smiles = self.globals['smiles']
      if '>>' in smiles or smiles.startswith('$RXN'):
        rxn = indigo.loadQueryReaction(smiles)
        rxn.layout()
        self.wfile.write("Ok.\n")
        self.wfile.write(rxn.rxnfile())
      else:
        mol = indigo.loadQueryMolecule(smiles)
        mol.layout()
        self.wfile.write("Ok.\n")
        self.wfile.write(mol.molfile())
      return

    if self.path.endswith("automap"):
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      smiles = self.globals['smiles']
      if 'mode' in self.globals:
        mode = self.globals['mode']
      else:
        mode = 'discard'
      rxn = indigo.loadQueryReaction(smiles)
      if not smiles.startswith('$RXN'):
        rxn.layout()
      rxn.automap(mode)
      self.wfile.write("Ok.\n")
      self.wfile.write(rxn.rxnfile())
      return

    SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Esempio n. 9
0
  def do_POST(self):
    ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
    if ctype == 'multipart/form-data':
      if self.path.endswith("open"):
        query = cgi.parse_multipart(self.rfile, pdict)
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        # Allow CORS and x-json
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Expose-Headers', 'x-json')
        self.end_headers()
        self.wfile.write("Ok.\n");
        self.wfile.write(query['filedata'][0]);
        return
      if self.path.endswith("save"):
        query = cgi.parse_multipart(self.rfile, pdict)
        filedata = query['filedata'][0]
        first = filedata.split("\n")[0]
        rest = "\n".join(filedata.split("\n")[1:])

        self.send_response(200)
        if first == "smi":
          self.send_header('Content-type', 'chemical/x-daylight-smiles')
        elif first == "mol":
          self.send_header('Content-type', 'chemical/x-mdl-molfile')
        else:
          self.send_header('Content-type', 'text/plain')

        self.send_header('Content-Disposition', 'attachment; filename=ketcher.' + first)
        # Allow CORS and x-json
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Expose-Headers', 'x-json')
        self.end_headers()
        self.wfile.write(rest)
      return

    if self.path.endswith("layout"):
      length = int(self.headers['content-length'])
      self.globals = dict(cgi.parse_qsl(self.rfile.read(length)))
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      # Allow CORS and x-json
      self.send_header('Access-Control-Allow-Origin', '*')
      self.send_header('Access-Control-Expose-Headers', 'x-json')
      self.end_headers()
      mol = indigo.loadQueryMolecule(self.globals['moldata'])
      mol.layout()
      self.wfile.write("Ok.\n")
      self.wfile.write(mol.molfile())
      return
Esempio n. 10
0
def handle_layout(request):
    if request.method == 'GET' and request.GET.has_key("smiles"):
        moldata = request.GET["smiles"]
    elif request.method == 'POST' and request.POST.has_key("moldata"):
        moldata = request.POST["moldata"]
    else:
        raise Http404
    if '>>' in moldata or moldata.startswith('$RXN'):
      rxn = indigo.loadQueryReaction(moldata)
      rxn.layout()
      return HttpResponse(content="Ok.\n" + rxn.rxnfile(), mimetype='text/plain')
    else:
      mol = indigo.loadQueryMolecule(moldata)
      mol.layout()
      return HttpResponse(content="Ok.\n" + mol.molfile(), mimetype='text/plain')
Esempio n. 11
0
 def load_moldata(self, is_query=False):
     moldata = self.fields.getfirst('moldata')
     if moldata.startswith('$RXN'):
         if is_query:
             md = indigo.loadQueryReaction(moldata)
         else:
             md = indigo.loadReaction(moldata)
         is_rxn = True
     else:
         if is_query:
             md = indigo.loadQueryMolecule(moldata)
         else:
             md = indigo.loadMolecule(moldata)
         is_rxn = False
     return md, is_rxn
Esempio n. 12
0
 def load_moldata(self, is_query=False):
     moldata = self.fields.getfirst('moldata')
     if moldata.startswith('$RXN'):
         if is_query:
             md = indigo.loadQueryReaction(moldata)
         else:
             md = indigo.loadReaction(moldata)
         is_rxn = True
     else:
         if is_query:
             md = indigo.loadQueryMolecule(moldata)
         else:
             md = indigo.loadMolecule(moldata)
         is_rxn = False
     return md, is_rxn
Esempio n. 13
0
    def on_layout(self):
        moldata = None
        if self.method == 'GET' and 'smiles' in self.fields:
            moldata = self.fields.getfirst('smiles')
        elif self.is_form_request() and 'moldata' in self.fields:
            moldata = self.fields.getfirst('moldata')

        if moldata:
            if '>>' in moldata or moldata.startswith('$RXN'):
                rxn = indigo.loadQueryReaction(moldata)
                rxn.layout()
                return ["Ok.\n", rxn.rxnfile()]
            else:
                mol = indigo.loadQueryMolecule(moldata)
                mol.layout()
                return ["Ok.\n", mol.molfile()]
        self.notsupported()
def handle_layout(request):
    if request.method == 'GET' and request.GET.has_key("smiles"):
        moldata = request.GET["smiles"]
    elif request.method == 'POST' and request.POST.has_key("moldata"):
        moldata = request.POST["moldata"]
    else:
        raise Http404
    if '>>' in moldata or moldata.startswith('$RXN'):
        rxn = indigo.loadQueryReaction(moldata)
        rxn.layout()
        return HttpResponse(content="Ok.\n" + rxn.rxnfile(),
                            mimetype='text/plain')
    else:
        mol = indigo.loadQueryMolecule(moldata)
        mol.layout()
        return HttpResponse(content="Ok.\n" + mol.molfile(),
                            mimetype='text/plain')
Esempio n. 15
0
    def on_layout(self):
        moldata = None
        if self.method == 'GET' and 'smiles' in self.fields:
            moldata = self.fields.getfirst('smiles')
        elif self.is_form_request() and 'moldata' in self.fields:
            moldata = self.fields.getfirst('moldata')

        if moldata:
            if '>>' in moldata or moldata.startswith('$RXN'):
                rxn = indigo.loadQueryReaction(moldata)
                rxn.layout()
                return ["Ok.\n",
                        rxn.rxnfile()]
            else:
                mol = indigo.loadQueryMolecule(moldata)
                mol.layout()
                return ["Ok.\n",
                        mol.molfile()]
        self.notsupported()
Esempio n. 16
0
  def do_POST(self):
    ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
    if ctype == 'multipart/form-data':
      if self.path.endswith("open"):
        query = cgi.parse_multipart(self.rfile, pdict)
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write("<html><body onload=\"parent.ui.loadMoleculeFromFile()\" title=\"");
        self.wfile.write(base64.b64encode("Ok.\n"));
        self.wfile.write(base64.b64encode(query['filedata'][0]));
        self.wfile.write("\"></body></html>");
        return
      if self.path.endswith("save"):
        query = cgi.parse_multipart(self.rfile, pdict)
        filedata = query['filedata'][0]
        lines = filedata.splitlines()
        first = lines[0].strip()
        rest = "\n".join(lines[1:])

        self.send_response(200)
        if first == "smi":
          self.send_header('Content-type', 'chemical/x-daylight-smiles')
        elif first == "mol":
          if rest.startswith('$RXN'):
            first = "rxn"
            self.send_header('Content-type', 'chemical/x-mdl-rxnfile')
          else:
            self.send_header('Content-type', 'chemical/x-mdl-molfile')
        else:
          self.send_header('Content-type', 'text/plain')

        self.send_header('Content-Length', len(rest))
        self.send_header('Content-Disposition', 'attachment; filename=ketcher.' + first)
        self.end_headers()
        self.wfile.write(rest)
      return

    if self.path.endswith("layout"):
      length = int(self.headers['content-length'])
      self.globals = dict(cgi.parse_qsl(self.rfile.read(length)))
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      moldata = self.globals['moldata']
      if '>>' in moldata or moldata.startswith('$RXN'):
        rxn = indigo.loadQueryReaction(moldata)
        rxn.layout()
        self.wfile.write("Ok.\n")
        self.wfile.write(rxn.rxnfile())
      else:
        mol = indigo.loadQueryMolecule(moldata)
        mol.layout()
        self.wfile.write("Ok.\n")
        self.wfile.write(mol.molfile())
      return

    if self.path.endswith("automap"):
      length = int(self.headers['content-length'])
      self.globals = dict(cgi.parse_qsl(self.rfile.read(length)))
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      moldata = self.globals['moldata']
      if 'mode' in self.globals:
        mode = self.globals['mode']
      else:
        mode = 'discard'
      rxn = indigo.loadQueryReaction(moldata)
      if not moldata.startswith('$RXN'):
        rxn.layout()
      rxn.automap(mode)
      self.wfile.write("Ok.\n")
      self.wfile.write(rxn.rxnfile())
      return