list - Identifying coordinate matches from two files using python -
i've got 2 sets of data describing atomic positions. they're in separate files compare, aim being identifying matching atoms coordinates. data looks following in both cases, , there's going 1000 or entries. files of different lengths since describe different sized systems , have following format:
1 , 0.000000000000e+00 0.000000000000e+00 2 , 0.000000000000e+00 2.468958660000e+00 3 , 0.000000000000e+00 -2.468958660000e+00 4 , 2.138180920454e+00 -1.234479330000e+00 5 , 2.138180920454e+00 1.234479330000e+00
the first column entry id, second set of coordinates in x,y.
what i'd compare coordinates in both sets of data, identify matches , corresponding id eg "entry 3 in file 1 corresponds entry 6 in file 2." i'll using information alter coordinate values within file 2.
i've read files, line line , split them 2 entries per line using command, put them list, bit stumped how specify comparison bit - particularly telling compare second entries only, whilst being able call first entry. i'd imagine require looping ?
code looks far:
open1 = open('./3x3supercell_coord_clean','r') opena = open('./6x6supercell_coord_clean','r') small_list=[] line in open1: stripped_small_line = line.strip() column_small = stripped_small_line.split(",") small_list.append(column_small) big_list=[] line in opena: stripped_big_line = line.strip() column_big = stripped_big_line.split(",") big_list.append(column_big) print small_list[2][1] #prints out coords
if doing trying compare second element of each element in 2 lists, can done having each coord compared against each coord in opposite file. not fastest way go it, should results need.it scans through small list, , checks every small_entry[1] (the coordinate) against every coordinate each entry in big_list
for small_entry in small_list: big_entry in big_list: if small_entry[1] == big_entry[1] : print(small_entry[0] + "matches" + big_entry[0])
something this?
Comments
Post a Comment