def convert_str(str_data, in_format, out_format): mol = OBMol() conv = OBConversion() conv.SetInFormat(in_format) conv.SetOutFormat(out_format) conv.ReadString(mol, str_data) return (conv.WriteString(mol), conv.GetOutFormat().GetMIMEType())
def convert_str(str_data, in_format, out_format, gen3d=False, add_hydrogens=False, perceive_bonds=False, out_options=None): # Make sure that the start of InChI is valid before passing it to # Open Babel, or Open Babel will crash the server. if in_format.lower() == 'inchi': validate_start_of_inchi(str_data) if out_options is None: out_options = {} obMol = OBMol() conv = OBConversion() conv.SetInFormat(in_format) conv.SetOutFormat(out_format) conv.ReadString(obMol, str_data) if add_hydrogens: obMol.AddHydrogens() if gen3d: # Generate 3D coordinates for the input mol = pybel.Molecule(obMol) mol.make3D() if perceive_bonds: obMol.ConnectTheDots() obMol.PerceiveBondOrders() for option, value in out_options.items(): conv.AddOption(option, conv.OUTOPTIONS, value) return (conv.WriteString(obMol), conv.GetOutFormat().GetMIMEType())