コード例 #1
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
 def read_package(self, p):
     for attr in ('line_width', 'font_size', 'font_family', 'line_color',
                  'area_color', 'paper_crop_svg', 'paper_orientation',
                  'paper_type', 'paper_crop_margin'):
         if p.getAttribute(attr):
             self.__dict__[attr] = p.getAttribute(attr)
     self.font_size = int(self.font_size)
     self.paper_crop_svg = int(self.paper_crop_svg)
     self.paper_crop_margin = int(self.paper_crop_margin)
     b = dom_extensions.getFirstChildNamed(p, 'bond')
     if b:
         self.bond_length = b.getAttribute('length') or self.bond_length
         self.bond_width = b.getAttribute('width') or self.bond_width
         self.double_length_ratio = b.getAttribute(
             'double-ratio') or self.double_length_ratio
         self.double_length_ratio = float(self.double_length_ratio)
         self.wedge_width = b.getAttribute(
             'wedge-width') or self.wedge_width
     a = dom_extensions.getFirstChildNamed(p, 'arrow')
     if a:
         self.arrow_length = a.getAttribute('length')
     a = dom_extensions.getFirstChildNamed(p, 'atom')
     if a:
         show_hydrogens = a.getAttribute('show_hydrogens')
         if show_hydrogens == "False":
             show_hydrogens = 0
         elif show_hydrogens == "True":
             show_hydrogens = 1
         self.show_hydrogens = int(show_hydrogens)
コード例 #2
0
ファイル: classes.py プロジェクト: sctincman/bkchem
 def read_package( self, p):
   for attr in ('line_width', 'font_size', 'font_family', 'line_color','area_color',
                'paper_crop_svg','paper_orientation','paper_type','paper_crop_margin'):
     if p.getAttribute( attr):
       self.__dict__[ attr] = p.getAttribute( attr)
   self.font_size = int( self.font_size)
   self.paper_crop_svg = int( self.paper_crop_svg)
   self.paper_crop_margin = int( self.paper_crop_margin)
   b = dom_extensions.getFirstChildNamed( p, 'bond')
   if b:
     self.bond_length = b.getAttribute( 'length') or self.bond_length
     self.bond_width = b.getAttribute( 'width') or self.bond_width
     self.double_length_ratio = b.getAttribute( 'double-ratio') or self.double_length_ratio
     self.double_length_ratio = float( self.double_length_ratio)
     self.wedge_width = b.getAttribute( 'wedge-width') or self.wedge_width
   a = dom_extensions.getFirstChildNamed( p, 'arrow')
   if a:
     self.arrow_length = a.getAttribute( 'length')
   a = dom_extensions.getFirstChildNamed( p, 'atom')
   if a:
     show_hydrogens = a.getAttribute('show_hydrogens')
     if show_hydrogens == "False":
       show_hydrogens = 0
     elif show_hydrogens == "True":
       show_hydrogens = 1
     self.show_hydrogens = int( show_hydrogens)
コード例 #3
0
ファイル: fragment.py プロジェクト: insilichem/bkchem
    def read_package(self, doc):
        self.id = doc.getAttribute("id")
        self.type = doc.getAttribute("type") or "explicit"
        name = dom_ext.getFirstChildNamed(doc, "name")
        if name:
            self.name = dom_ext.getAllTextFromElement(name)
        for b in dom_ext.simpleXPathSearch(doc, "bond"):
            try:
                self.edges.add(
                    Store.id_manager.get_object_with_id(b.getAttribute("id")))
            except KeyError:
                raise bkchem_fragment_error("inconsistent", "")

        for v in dom_ext.simpleXPathSearch(doc, "vertex"):
            try:
                self.vertices.add(
                    Store.id_manager.get_object_with_id(v.getAttribute("id")))
            except KeyError:
                raise bkchem_fragment_error("inconsistent", "")

        for p in dom_ext.simpleXPathSearch(doc, "property"):
            k = p.getAttribute("name")
            v = p.getAttribute("value")
            t = p.getAttribute("type")
            typ = types.__dict__[t]
            self.properties[k] = typ(v)
コード例 #4
0
ファイル: external_data.py プロジェクト: insilichem/bkchem
    def read_data_definition(self, filename):
        doc = dom.parse(filename)
        root = doc.childNodes[0]
        for ecls in dom_ext.simpleXPathSearch(root, "class"):
            cls = ecls.getAttribute('name')
            self.definitions[cls] = {}
            for eobj in dom_ext.simpleXPathSearch(ecls, "object"):
                obj = eobj.getAttribute('type')
                self.definitions[cls][obj] = {}
                for evalue in dom_ext.simpleXPathSearch(eobj, "value"):
                    vname = evalue.getAttribute('name')
                    vtype = evalue.getAttribute('type')
                    # try to decode list style types
                    if vtype.startswith("[") and vtype.endswith("]"):
                        try:
                            vtype = eval(vtype)
                        except ValueError:
                            pass
                    text = dom_ext.getAllTextFromElement(
                        dom_ext.getFirstChildNamed(evalue, "text"))
                    self.definitions[cls][obj][vname] = {
                        'type': vtype,
                        'text': text
                    }

        self.records[cls] = {}
コード例 #5
0
 def _read_atom(self, at, mol):
     a = atom(self.paper, molecule=mol)
     a.set_name(
         dom_ext.getAllTextFromElement(
             dom_ext.getFirstChildNamed(at, "symbol")))
     coords = dom_ext.getFirstChildNamed(at, "coordinates")
     a.x = float(
         dom_ext.getAllTextFromElement(
             dom_ext.getFirstChildNamed(coords, "x")))
     a.y = float(
         dom_ext.getAllTextFromElement(
             dom_ext.getFirstChildNamed(coords, "y")))
     a.z = float(
         dom_ext.getAllTextFromElement(
             dom_ext.getFirstChildNamed(coords, "z")))
     a.show_hydrogens = int(a.name != 'C')
     # charge
     chel = dom_ext.getFirstChildNamed(at, "charge")
     if chel:
         a.charge = int(dom_ext.getAllTextFromElement(chel))
     # multiplicity
     radical = dom_ext.getFirstChildNamed(at, "radical")
     if radical:
         a.multiplicity = 1 + int(dom_ext.getAllTextFromElement(radical))
     # remap of ids
     self._atom_id_remap[at.getAttribute('id')] = a
     return a
コード例 #6
0
ファイル: gtml.py プロジェクト: bartlebee/bkchem
 def _read_atom(self, at, mol):
     a = atom(self.paper, molecule=mol)
     a.set_name(dom_ext.getAllTextFromElement(dom_ext.getFirstChildNamed(at, "symbol")))
     coords = dom_ext.getFirstChildNamed(at, "coordinates")
     a.x = float(dom_ext.getAllTextFromElement(dom_ext.getFirstChildNamed(coords, "x")))
     a.y = float(dom_ext.getAllTextFromElement(dom_ext.getFirstChildNamed(coords, "y")))
     a.z = float(dom_ext.getAllTextFromElement(dom_ext.getFirstChildNamed(coords, "z")))
     a.show_hydrogens = int(a.name != "C")
     # charge
     chel = dom_ext.getFirstChildNamed(at, "charge")
     if chel:
         a.charge = int(dom_ext.getAllTextFromElement(chel))
     # multiplicity
     radical = dom_ext.getFirstChildNamed(at, "radical")
     if radical:
         a.multiplicity = 1 + int(dom_ext.getAllTextFromElement(radical))
     # remap of ids
     self._atom_id_remap[at.getAttribute("id")] = a
     return a
コード例 #7
0
ファイル: external_data.py プロジェクト: bartlebee/bkchem
  def read_data_definition( self, filename):
    doc = dom.parse( filename)
    root = doc.childNodes[0]
    for ecls in dom_ext.simpleXPathSearch( root, "class"):
      cls = ecls.getAttribute( 'name')
      self.definitions[ cls] = {}
      for eobj in dom_ext.simpleXPathSearch( ecls, "object"):
        obj = eobj.getAttribute( 'type')
        self.definitions[ cls][ obj] = {}
        for evalue in dom_ext.simpleXPathSearch( eobj, "value"):
          vname = evalue.getAttribute( 'name')
          vtype = evalue.getAttribute( 'type')
          # try to decode list style types
          if vtype.startswith( "[") and vtype.endswith( "]"):
            try:
              vtype = eval( vtype)
            except ValueError:
              pass
          text = dom_ext.getAllTextFromElement( dom_ext.getFirstChildNamed( evalue, "text"))
          self.definitions[ cls][ obj][ vname] = {'type': vtype,
                                                  'text': text }

    self.records[ cls] = {}
コード例 #8
0
ファイル: fragment.py プロジェクト: bartlebee/bkchem
  def read_package( self, doc):
    self.id = doc.getAttribute( "id")
    self.type = doc.getAttribute( "type") or "explicit"
    name = dom_ext.getFirstChildNamed( doc, "name")
    if name:
      self.name = dom_ext.getAllTextFromElement( name)
    for b in dom_ext.simpleXPathSearch( doc, "bond"):
      try:
        self.edges.add( Store.id_manager.get_object_with_id( b.getAttribute( "id")))
      except KeyError:
        raise bkchem_fragment_error( "inconsistent", "")

    for v in dom_ext.simpleXPathSearch( doc, "vertex"):
      try:
        self.vertices.add( Store.id_manager.get_object_with_id( v.getAttribute( "id")))
      except KeyError:
        raise bkchem_fragment_error( "inconsistent", "")

    for p in dom_ext.simpleXPathSearch( doc, "property"):
      k = p.getAttribute( "name")
      v = p.getAttribute( "value")
      t = p.getAttribute( "type")
      typ = types.__dict__[ t]
      self.properties[k] = typ( v)