def export_CD_SVG(paper, filename, gzipped=0): """Export to CD-SVG. Return 1 on success, 0 otherwise. Optionally compress with gzip. """ try: if gzipped: import gzip f = gzip.open(filename, "wb") else: f = open(filename, "wb") except IOError as x: return 0 exporter = xml_writer.SVG_writer(paper) exporter.construct_dom_tree(paper.top_levels) doc = exporter.document cdml = paper.get_package().childNodes[0] doc.childNodes[0].appendChild(cdml) dom_extensions.safe_indent(doc.childNodes[0], dont_indent=("text", "ftext", "user-data")) s = doc.toxml('utf-8') f.write(s) f.close() return 1
def get_nicely_formated_document(self): """Return text form of self.document. Indented with dom_extensions.safe_indent. """ dom_extensions.safe_indent( self.top, dont_indent=("text","ftext","user-data")) return self.document.toxml('utf-8')
def get_nicely_formated_document(self): """Return text form of self.document. Indented with dom_extensions.safe_indent. """ dom_extensions.safe_indent(self.top, dont_indent=("text", "ftext", "user-data")) return self.document.toxml('utf-8')
def write_to_file( self, name): out = dom.Document() root = dom_ext.elementUnder( out, 'cml') for m in self.paper.molecules: mol = dom_ext.elementUnder( root, 'molecule') if m.id: mol.setAttribute( 'id', m.id) atoms = dom_ext.elementUnder( mol, 'atomArray') for a in m.atoms: atoms.appendChild( self.CML_atom( atom=a, scaling=self.scale).get_CML_dom( out)) bonds = dom_ext.elementUnder( mol, 'bondArray') for b in m.bonds: bonds.appendChild( self.CML_bond( bond=b).get_CML_dom( out)) dom_ext.safe_indent( root) with open(name, 'wb') as f: f.write(out.toxml('utf-8'))
def export_CDML(paper, filename, gzipped=0): """Export to CDML. Rreturn 1 on success, 0 otherwise. Optionally compress with gzip. """ try: if gzipped: import gzip f = gzip.open(filename, "wb") else: f = open(filename, "wb") except IOError as x: return 0 doc = paper.get_package() dom_extensions.safe_indent(doc.childNodes[0], dont_indent=("text", "ftext", "user-data")) s = doc.toxml('utf-8') f.write(s) f.close() return 1
def export_CD_SVG( paper, filename, gzipped=0): """exports to CD-SVG, returns 1 on success, 0 otherwise; optionally compresses with gzip""" if gzipped: import gzip as module else: import __builtin__ as module try: inp = module.open( filename, "w") except IOError, x: return 0 exporter = xml_writer.SVG_writer( paper) exporter.construct_dom_tree( paper.top_levels) doc = exporter.document cdml = paper.get_package().childNodes[0] doc.childNodes[0].appendChild( cdml) dom_extensions.safe_indent( doc.childNodes[0], dont_indent=("text","ftext","user-data")) inp.write( unicode(doc.toxml()).encode('utf-8')) inp.close() return 1 def export_CDML( paper, filename, gzipped=0): """exports to CDML, returns 1 on success, 0 otherwise; optionally compresses with gzip""" if gzipped: import gzip as module else: import __builtin__ as module try: inp = module.open( filename, "w") except IOError, x: return 0