import os, sys, argparse, glob
import General, PDB
selfbin = General.selfbin(sys.argv[0])

par = argparse.ArgumentParser()
par.add_argument('--head', required = True, help = 'head of files')
par.add_argument('--id', default = '0.4', help = 'identity cutoff')
par.add_argument('--db', help = 'database, if not specified, use default')
par.add_argument('--conR', action = 'store_true', help = 'whether this is for a pair of contact')
par.add_argument('--env', help = 'if not None, also modify an .env file')
args = par.parse_args()

dirs = [x for x in os.listdir('.') if os.path.isdir(x)]
dirs.sort()
odir = os.getcwd()

for d in dirs:
	os.chdir(odir)
	os.chdir(d)
	pdbs = glob.glob('*.pdb')
	cmds = []
	resn = int(d.split('_')[1][2:])
	for pdb in pdbs:
		matchf = args.head + '_' + General.changeExt(pdb, 'match')
		if not os.path.isfile(matchf):
			continue

		pos = PDB.findPositionInPDB(pdb, resn)
		# if output file is already there, skip the job
		if os.path.isfile('nr'+args.id +'_'+matchf):
			continue