Example #1
0
def cairo_out_test():
    import molfile
    import time
    cid = 22646404
    #cid = 1373132
    #cid = 18305969
    #cid = 19815256
    f = file("%d.mol" % cid, "r")
    mol = molfile.file_to_mol(f)
    f.close()
    import cairo_out
    mol.normalize_bond_length(25)
    mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out(scaling=4.0,
                            margin=10,
                            font_size=16,
                            bond_second_line_shortening=0.15,
                            bond_width=6,
                            line_width=2.0,
                            antialias_drawing=True,
                            antialias_text=True)
    #c.background_color = (1,1,0.6)
    c.show_hydrogens_on_hetero = True
    t = time.time()
    c.mol_to_cairo(mol, "%d.png" % cid)
    c.mol_to_cairo(mol, "%d.pdf" % cid, format="pdf")
    c.mol_to_cairo(mol, "%d.svg" % cid, format="svg")
    print time.time() - t
Example #2
0
def test_multimol_molfile():
    import molfile
    f = file('test.mol', 'r')
    mol = molfile.file_to_mol(f)
    f.close()
    print mol.is_connected()
    for mol in mol.get_disconnected_subgraphs():
        print mol
Example #3
0
def test_multimol_molfile():
    import molfile
    f = file( 'test.mol', 'r')
    mol = molfile.file_to_mol( f)
    f.close()
    print mol.is_connected()
    for mol in mol.get_disconnected_subgraphs():
        print mol
Example #4
0
def test_charge_property_line():
    import molfile
    f = file('fromOBabel.mol', 'r')
    mol = molfile.file_to_mol(f)
    f.close()
    print mol.is_connected()
    for mol in mol.get_disconnected_subgraphs():
        for atom in mol.atoms:
            print atom.charge
Example #5
0
def test_charge_property_line():
    import molfile
    f = file( 'fromOBabel.mol', 'r')
    mol = molfile.file_to_mol( f)
    f.close()
    print mol.is_connected()
    for mol in mol.get_disconnected_subgraphs():
        for atom in mol.atoms:
            print atom.charge
Example #6
0
def cairo_out_test_wedge():
    import molfile
    import time
    f = file( "untitled0.mol", "r")
    mol = molfile.file_to_mol( f)
    f.close()
    import cairo_out
    mol.normalize_bond_length( 30)
    mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out( scaling=1.0, antialias_text=True, color_bonds=True, color_atoms=True)
    t = time.time()
    c.mol_to_cairo( mol, "untitled0.png")
    print time.time()-t
Example #7
0
def cairo_out_test3d():
    import molfile
    f = file( "1.mol", "r")
    mol = molfile.file_to_mol( f)
    f.close()
    import cairo_out
    #mol.normalize_bond_length( 25)
    #mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out( scaling=1.0, margin=30, font_size=16,
                             bond_second_line_shortening=0.15, bond_width=6,
                             line_width=2.0, antialias_drawing=True,
                             antialias_text=True)
    c.show_hydrogens_on_hetero = True
    c.mol_to_cairo( mol, "1.png")
Example #8
0
def cairo_out_test_wedge():
    import molfile
    import time
    f = file("untitled0.mol", "r")
    mol = molfile.file_to_mol(f)
    f.close()
    import cairo_out
    mol.normalize_bond_length(30)
    mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out(scaling=1.0,
                            antialias_text=True,
                            color_bonds=True,
                            color_atoms=True)
    t = time.time()
    c.mol_to_cairo(mol, "untitled0.png")
    print time.time() - t
Example #9
0
def cairo_out_test3d():
    import molfile
    f = file("1.mol", "r")
    mol = molfile.file_to_mol(f)
    f.close()
    import cairo_out
    #mol.normalize_bond_length( 25)
    #mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out(scaling=1.0,
                            margin=30,
                            font_size=16,
                            bond_second_line_shortening=0.15,
                            bond_width=6,
                            line_width=2.0,
                            antialias_drawing=True,
                            antialias_text=True)
    c.show_hydrogens_on_hetero = True
    c.mol_to_cairo(mol, "1.png")
Example #10
0
def cairo_out_test():
    import molfile
    import time
    cid = 22646404
    #cid = 1373132
    #cid = 18305969
    #cid = 19815256
    f = file( "%d.mol" % cid, "r")
    mol = molfile.file_to_mol( f)
    f.close()
    import cairo_out
    mol.normalize_bond_length( 25)
    mol.remove_unimportant_hydrogens()
    c = cairo_out.cairo_out( scaling=4.0, margin=10, font_size=16,
                             bond_second_line_shortening=0.15, bond_width=6,
                             line_width=2.0, antialias_drawing=True,
                             antialias_text=True)
    #c.background_color = (1,1,0.6)
    c.show_hydrogens_on_hetero = True
    t = time.time()
    c.mol_to_cairo( mol, "%d.png" % cid)
    c.mol_to_cairo( mol, "%d.pdf" % cid, format="pdf")
    c.mol_to_cairo( mol, "%d.svg" % cid, format="svg")
    print time.time()-t
Example #11
0
                                       ( 'ry', str( radius)),
                                       ( 'stroke-width', "1"),
                                       ( 'fill', fill_color),
                                       ( 'stroke', stroke_color),
                                       ( 'fill-opacity', str(opacity)),
                                       ( 'stroke-opacity', str(opacity)),
                                      ))
    if id:
      el.setAttribute( "id", id)


def mol_to_svg( mol, filename):
  c = svg_out()
  tree = c.mol_to_svg( mol)
  f = file( filename, "w")
  f.write( tree.toxml())
  f.close()


if __name__ == "__main__":

  #import inchi
  #mol = inchi.text_to_mol( "1/C7H6O2/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H,8,9)", include_hydrogens=False, calc_coords=30)
  #import smiles
  #mol = smiles.text_to_mol( "CC[CH]", calc_coords=40)
  import molfile
  mol = molfile.file_to_mol( file( "/home/beda/bkchem/bkchem/untitled0.mol", "r"))
  mol_to_svg( mol, "output.svg")


Example #12
0
    import time

    pmol = pybel.readstring("smi", "CC(=O)O")
    omol = PybelConverter.pybel_to_oasa_molecule(pmol)
    print(omol)
    import smiles
    c = smiles.converter()
    print(c.mols_to_text([omol]))

    #print(get_supported_input_formats())
    #print(get_supported_output_formats())

    if False:
        import molfile
        with open("tbu-benzen.mol", 'r') as f:
            mol = molfile.file_to_mol(f)

        print(PybelConverter.oasa_to_pybel_molecule(mol))

        t = time.time()
        ff = ForceFieldOptimizer(mol)
        gen = ff.conjugate_gradients()
        for step in gen:
            print(step, ff.ff.Energy())
            ff.update_coords()
            print([a.coords for a in mol.atoms])
        print(time.time() - t)

    a = pybel.readstring("smi", "CCCC\nCCC")

    for mol in PybelConverter.read_text("smi", "CCCC\nCCC"):
Example #13
0
def stereo_from_coords():
    f = file("ez_stereo2.mol", "r")
    mol = molfile.file_to_mol(f)
    f.close()
    mol.detect_stereochemistry_from_coords()
    print smiles.mol_to_text(mol)
Example #14
0
def stereo_from_coords2():
    f = file("cis_trans_cycles.mol", "r")
    mol = molfile.file_to_mol(f)
    f.close()
    c = smiles.converter()
    print c.mols_to_text([mol])
Example #15
0
def stereo_from_coords():
    f = file( "ez_stereo2.mol", "r")
    mol = molfile.file_to_mol( f)
    f.close()
    mol.detect_stereochemistry_from_coords()
    print smiles.mol_to_text( mol)
Example #16
0
            ('rx', str(radius)),
            ('ry', str(radius)),
            ('stroke-width', "1"),
            ('fill', fill_color),
            ('stroke', stroke_color),
            ('fill-opacity', str(opacity)),
            ('stroke-opacity', str(opacity)),
        ))
        if id:
            el.setAttribute("id", id)


def mol_to_svg(mol, filename):
    c = svg_out()
    tree = c.mol_to_svg(mol)
    f = file(filename, "w")
    f.write(tree.toxml())
    f.close()


if __name__ == "__main__":

    #import inchi
    #mol = inchi.text_to_mol( "1/C7H6O2/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H,8,9)", include_hydrogens=False, calc_coords=30)
    #import smiles
    #mol = smiles.text_to_mol( "CC[CH]", calc_coords=40)
    import molfile
    mol = molfile.file_to_mol(
        file("/home/beda/bkchem/bkchem/untitled0.mol", "r"))
    mol_to_svg(mol, "output.svg")
Example #17
0
  import time

  pmol = pybel.readstring("smi", "CC(=O)O")
  omol = PybelConverter.pybel_to_oasa_molecule( pmol)
  print(omol)
  import smiles
  c = smiles.converter()
  print(c.mols_to_text([omol]))

  #print(get_supported_input_formats())
  #print(get_supported_output_formats())

  if False:
    import molfile
    with open("tbu-benzen.mol", 'r') as f:
      mol = molfile.file_to_mol(f)

    print(PybelConverter.oasa_to_pybel_molecule(mol))

    t = time.time()
    ff = ForceFieldOptimizer( mol)
    gen = ff.conjugate_gradients()
    for step in gen:
      print(step, ff.ff.Energy())
      ff.update_coords()
      print([a.coords for a in mol.atoms])
    print(time.time() - t)

  a = pybel.readstring( "smi", "CCCC\nCCC")

  for mol in PybelConverter.read_text( "smi", "CCCC\nCCC"):
Example #18
0
def stereo_from_coords2():
    f = file( "cis_trans_cycles.mol", "r")
    mol = molfile.file_to_mol( f)
    f.close()
    c = smiles.converter()
    print c.mols_to_text( [mol])