Python calculate minimum distances between multiple coordinates -


i have files in 2 type: a: contains 1206 lines of coordinates (xyz) - protein chain b: contains 114 lines of coordinates (xyz) - bunch of molecule

i followings: each line of calculate distance each line of b. 114 distance value each line of a. don't need of them, shortest each line of a. desired output: file 1206 lines, each line contains 1 value: shortest distance. important keep original order of file a.

my code:

import os import sys import numpy np    outdir = r'e:\mta\aminosavak_tavolsag\tavolsagok' dirname, dirnames, filenames in os.walk(r'e:\mta\aminosavak_tavolsag\receptorok'):     path, dirs, files in os.walk(r'e:\mta\aminosavak_tavolsag\kotohely'):         filename in filenames:             fileok in files:                 if filename == fileok:                     open(os.path.join(outdir, filename) , "a+") f:                         data_ligand = np.loadtxt(os.path.join(path, fileok))                         data_rec = np.loadtxt(os.path.join(dirname, filename))                          in data_rec:                             j in data_ligand:                                  dist = np.linalg.norm(i - j)                                  dist_float = dist.tolist()                                   dist_str = str(dist_float)                                 dist_list = dist_str.split()                                 szamok in dist_list:                                     x in range(len(dist_list)):                                         minimum = min([float(x) x in dist_list])                              f.write(str(minimum) + "\r\n") 

this code works partially. --- ultimate goal find protein residues close enough bunch of molecule (binding site). can check results visual software , code find more less residues should. ----

i can't figure out problem. me? thanks!

your code pretty confusing , can see few mistakes.

you're using minimum outside of for loop, last value written.

also, way computes minimum wierd. szamok not used, nor x (since use x inside list expression), both for loops surrounding minimum = ... useless.

another suspicious thing str(dist_float). you're converting list of float string. give string representation of list, not list of string. not useless, it's wrong because when split after won't give expected result.

assuming i , j stands data lines of , b, rewrite end of code this:

... data_ligand = np.loadtxt(os.path.join(path, fileok)) data_rec = np.loadtxt(os.path.join(dirname, filename))  in data_rec:     min_dist = min(np.linalg.norm(i - j) j in data_ligand)     f.write("{}\r\n".format(min_dist))  # easier `str(min_dist)` customize format 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -