How to use the pybel.readstring function in pybel

To help you get started, we’ve selected a few pybel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Helpsypoo / primer / draw_molecules / run.py View on Github external
else:
        chemformat = args.format

    if not pybel.informats:
        sys.stderr.write("Open babel not properly installed. Exiting.\n")
        sys.exit()
    if chemformat not in pybel.informats:
        prefix = "Inferred" if args.format == 'auto' else "Supplied"
        formats = ', '.join(pybel.informats.keys())
        sys.stderr.write(("{} format '{}' not in available open babel formats."
                          "\n\nSupported formats:\n{}\n"
                          ).format(prefix, chemformat, formats))
        sys.exit()

    try:
        mol = pybel.readstring(chemformat, data)
    except OSError:
        prefix = "Inferred" if args.format == 'auto' else "Supplied"
        debug = ((" - Read input as file." if is_file else
                 " - Inferred input as string, not file.") +
                 "\n - {} format of '{}'.".format(prefix, chemformat))
        sys.stderr.write("Could not read molecule.\n\nDebug:\n" + debug + "\n")
        sys.exit()

    json_mol = process(mol, args.hydrogens, args.generate_coords,
                       args.infer_bonds, args.convert_only)
    #print(json_mol)
    if args.convert_only:
        print(json_mol)
        sys.exit()

    mac_path = '/Applications/blender.app/Contents/MacOS/./blender'
github patrickfuller / blender-chemicals / molecule_to_json.py View on Github external
"    data: Chemical file or string\n"
               "    --addh:  add hydrogen atoms")
        exit()

    # "smi", "mol", "cif", etc.
    molecule_type = argv[1]

    # Support both files and strings.
    try:
        with open(argv[2]) as in_file:
            in_data = in_file.read()
    except:
        in_data = argv[2]

    # Load openbabel molecule
    molecule = pybel.readstring(molecule_type, in_data)
    molecule.addh()

    # User specified args to generate coordinates and keep hydrogen atoms
    if molecule_type == "smi":
        molecule.make3D(steps=500)
    if "--addh" not in argv:
        molecule.removeh()

    # Print result to stdout for piping and what not
    print json_formatter.dumps(molecule_to_json(molecule))
github dkoes / qsar-tools / outputfingerprints.py View on Github external
fp = MACCSkeys.GenMACCSKeys(mol)
        return [int(x) for x in fp.ToBitString()]
    elif args.fp == 'smarts':
        if args.smartsfile:
            smarts = args.smartsfile
            ret = [0]*len(smarts)
            for (i,smart) in enumerate(smarts):
                if mol.HasSubstructMatch(smart):
                    ret[i] = 1
            return ret
        else:
            sys.stderr.write("ERROR: Must provide SMARTS file with --smarts\n")
            sys.exit(-1)
    elif args.fp == 'fp2':
        smi = Chem.MolToSmiles(mol) 
        obmol = pybel.readstring('smi',smi)
        fp = obmol.calcfp(fptype='FP2')
        ret = [0]*1021 #FP2 are mod 1021
        for setbit in fp.bits:
            #but pybel makes the bits start at 1 for some reason
            assert(setbit>0)
            ret[setbit-1] = 1
            
        return ret
        
    else:
        return []
github pnnl / isicle / isicle / preprocess.py View on Github external
def desalt(smi):
    mol = pybel.readstring('smi', smi)
    mol.OBMol.StripSalts()
    return mol.write('can').strip()
github loftytopping / PyBox / Aerosol / f2py / Aerosol_simulation_f2py.py View on Github external
core_density_array=[1770.0]*num_bins #[kg/m3] - need to make sure this matches core definition above
    core_mw=[132.14]*num_bins #[g/mol]
    #Calculate a concentration, in molecules per cc, per size bin of the involatile material
    #The size bins, 'x', are given in microns. 
    core_type='Inorganic' #Label to be used in non-ideal model variants. It is useful to
    #Define the SMARTS representations of relevant ions for use in proeeding calculations. These can be
    #seleted from the following:
    #[Na+] Sodium cation
    #[NH4+] Ammonium cation
    #[K+] Potassium cation
    #[Ca+2] Calcium cation
    #[Mg+2] Magnesium cation
    #[Cl-] Chloride anion
    #[O-][N+]([O-])=O Nitrate anion
    #[O-]S([O-])(=O)=O Sulphate anion
    key_ion1=pybel.readstring('smi','[NH4+]')
    key_ion2=pybel.readstring('smi','[O-]S([O-])(=O)=O')
    ammonium_key=key_ion1
    sulphate_key=key_ion2
    #Update the species_dict2array to include the ions
    species_dict2array.update({ammonium_key:num_species})
    species_dict2array.update({sulphate_key:num_species+1})
    cation_index=[0] #used to extract ion concentrations from within the simulation - use order from above [defunct for now]
    anion_index=[1]
    
    core_dissociation=3.0 #Define this according to choice of core type. Please note this value might change
    y_core=(4.0/3.0)*numpy.pi*numpy.power(numpy.array(x*1.0e-6),3.0) #4/3*pi*radius^3
    y_core=y_core*numpy.array(core_density_array) #mass per particle [kg]
    y_core=y_core/(numpy.array(core_mw)*1.0e-3) #moles per particle, changing mw from g/mol to kg/mol
    y_core=y_core*NA #molecules per particle
    y_core=y_core*numpy.array(N_perbin) #molecules/cc representing each size range
    #Calculate a core mass based on the above information [converting from molecules/cc to micrograms/m3]    
github ReactionMechanismGenerator / ARC / arc / species / xyz_to_2d.py View on Github external
def to_pybel_mol(self, from_coords=True):
        """
        Convert the graph to a Pybel molecule. Currently only supports
        creating the molecule from 3D coordinates.
        """
        if from_coords:
            xyz = self.to_xyz()
            try:
                mol = pybel.readstring('xyz', xyz)
            except IOError:
                return None
            return mol
        else:
            raise NotImplementedError('Can only create Pybel molecules from 3D structure')
github schneiderfelipe / pnictogen / pnictogen / helpers.py View on Github external
if molecule.dim < 3:
        molecule.make3D()

    copy_molecule = pybel.readstring(copyformat, molecule.write(copyformat))

    cs = pybel.ob.OBConformerSearch()
    cs.Setup(copy_molecule.OBMol, nconf, children, mutability, convergence)

    cs.Search()
    cs.GetConformers(copy_molecule.OBMol)

    conformers = []
    for i in range(copy_molecule.OBMol.NumConformers()):
        copy_molecule.OBMol.SetConformer(i)
        conformers.append(pybel.readstring(copyformat,
                                           copy_molecule.write(copyformat)))
    return conformers
github metaspace2020 / metaspace / metaspace / engine / scripts / mol_structure_svg_gen.py View on Github external
def generateSvg(inchi, filename):
    if os.path.exists(filename):
        return
    mol = pybel.readstring('inchi', inchi)
    mol.write('svg', filename=filename)
github pnnl / isicle / isicle / preprocess.py View on Github external
def smi2inchi(smi):
    '''Converts SMILES string to InChI string.'''

    return pybel.readstring('smi', smi).write('inchi').strip()