If you working in python this should help you.
I wrote these scripts when using obspectrophores. "get_spectrophore.py"
will get you a compound spectrophore (tested with sdf but should work with
other obabel supported format).The second one will compute their euclidean
distances.
def get_spectrophore(ligand):
    import subprocess
    import numpy as np
    """
    :param : ligand
    :return: obspectrophore in python dictionary form {compound : spectrophore}.
    """
    executable = "obspectrophore" #path to obspectrophore executable 

    cmd = [ executable, '-i', ligand]
    try: 
        output = subprocess.check_output(cmd, stderr= 
subprocess.STDOUT).decode('ascii') #check_output
        output = [e for e  in output.split("Angstrom")[-1].split("\n")][2:-1]
        output = [e.split("\t")[:-1] for e  in output]
        out_dict =  {}
        for e in output:
            out_dict[e[0]] = np.array([ float(e) for e in e[1:]])
        output = out_dict
    except subprocess.CalledProcessError as e:
                sys.stderr.write(e.output.decode('ascii'))          
    return output 

ligands = "test.sdf"
print(get_spectrophore(ligands))
def obspectrophores_euclidean(ligand1, ligand2):
        import numpy as np
    """
    :param ligand1
    :param ligand2
    :return:euclidean distance of their obspectrophores.
    """
    score = ""
    ligand1_spectrophore = get_spectrophore(ligand1)
    ligand2_spectrophore = get_spectrophore(ligand2)
    scores =[] #{('ZINC000000000221', 'ZINC000000000221'): 0.0 key: tuple of 
ligand, value: euclidean distance 
    for lig2 in ligand2_spectrophore:
        for lig1 in ligand1_spectrophore:
            spec_euc_dist = np.linalg.norm((ligand1_spectrophore[lig1] - 
ligand2_spectrophore[lig2]))
            scores.append((lig1, lig2, spec_euc_dist))

    return scores

test_ligand = "test.sdf"

print(obspectrophores_euclidean(test_ligand, test_ligand)) #should return zero
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to