#############################################
# P. Sen, February 2021
#
# This script reads two files, one containing 
# features generated/extracted by query-newgeatures.py
# and the other containing ACSF and sine matrix. 
# It then matches ids of the materials in the two files,
# and whenever there is match, the two sets of features
# for the materil is combined into a single line. 
# Each file should use the same ids for the compounds.
# for matches to occur.
#############################################

# Open the files containing old features, and
# those derived from describe
outcar1 = open('data-file.txt', 'r')
outcar2 = open('features-frm-dscribe', 'r')

# Read in the contents of the two files
content1 = outcar1.readlines()
content2 = outcar2.readlines()

# Compare compound ids from the two files
for i in range(len(content1)):
	words1 = content1[i].split('\t')
	new = content1[i][:-1]
	for j in range(len(content2)):
	        words2 = content2[j].split('\t')

# If the ids match, merge the lines from the two files
	        if (words1[0] == words2[0]):
	                #print('i, j ', (i,j))
	                k = 1
	                while k < len(words2):
	                        #print('k= ',k)
	                        new = new + '\t' + words2[k]
	                        k += 1
	                print(new[:-1])
