def main(argv):
	if len(argv) != 5:
		print('USAGE: <native pdb file> <pdb file> <model limit> <output file prefix> <lrmsd criteria>')
		sys.exit(2)
	try: #TODO: add better checking here
		native_in = str(argv[0])
		file_in = str(argv[1])
		nr_models = int(argv[2])
		output_prefix = str(argv[3])
		lrmsd_criteria = int(argv[4])
	except:
		print('USAGE: <native pdb file> <pdb file> <model limit> <output file prefix> <lrmsd criteria>')
		sys.exit(2)
	#Create lists of conformations	
	labels, nativeconformation, conformations = Parser.PDB(native_in, file_in, nr_models)
	#Sort into positive and negative sets using lRMSD 
	withinlRMSD, morethanlRMSD = Distance.sortBylRMSDs(nativeconformation, conformations, lrmsd_criteria)
	
	#output image of native graph
	#nativeGraph = nx.Graph()
	#curr_conf = nativeconformation[0]
	#for j in range(len(curr_conf)-RES_DISTANCE):
	#	for k in range(j+RES_DISTANCE, len(curr_conf)):
	#		atom1 = curr_conf[j]
	#		atom2 = curr_conf[k]
	#		#add nodes to graph with labels
	#		nativeGraph.add_node(j)
	#		nativeGraph.node[j]['aminoAcid'] = labels[j]
	#		nativeGraph.add_node(k)
	#		nativeGraph.node[k]['aminoAcid'] = labels[k]
	#		#find euclidean distance between atoms
	#		d = Distance.euclideanDistance(atom1, atom2)
	#		#if less than BIN_CRITERIA, add edge
	#		if(d <= BIN_CRITERIA):
	#			nativeGraph.add_edge(j, k, distance=d)
	#printGraph(nativeGraph, 'Output/PosGraphs/native')
	
	#output graph attributes for each data set
	#Note: removed newline='' from open() for linux
	dt = time.strftime("_%Y%m%d-%H%M%S")
	with open('Output/'+output_prefix+dt+'.csv', 'w') as csvfile:
		writer = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
		writer.writerow(['num_edges', 'density','avg_degree','percent_endpoints','energy', 'second_eigen', 'unique_eigen', 'spectral_rad', 'inverse_product',
			'link_impurity', 'neighborhood_impurity', 'avg_closeness', 'avg_clustering', 'small_worldness','eccentricity','diameter',
			'radius','%central_nodes', '%Hydrophobic_center', 'near_native'])
		#Positive Data Set
		for i in range(len(withinlRMSD)):
			graph = nx.Graph()
			curr_conf = withinlRMSD[i]
			for j in range(len(curr_conf)-RES_DISTANCE):
				for k in range(j+RES_DISTANCE, len(curr_conf)):
					atom1 = curr_conf[j]
					atom2 = curr_conf[k]
					#add nodes to graph with labels
					graph.add_node(j)
					graph.node[j]['aminoAcid'] = labels[j]
					if(labels[j] in HPHOBIC):
						graph.node[j]['hydro'] = 'phobic'
					else:
						graph.node[j]['hydro'] = 'philic'
					graph.add_node(k)
					graph.node[k]['aminoAcid'] = labels[k]
					if(labels[k] in HPHOBIC):
						graph.node[k]['hydro'] = 'phobic'
					else:
						graph.node[k]['hydro'] = 'philic'
					#find euclidean distance between atoms
					d = Distance.euclideanDistance(atom1, atom2)
					#if less than BIN_CRITERIA, add edge
					if(d <= BIN_CRITERIA):
						graph.add_edge(j, k, distance=d)
			##FOR TESTING ONLY
			#printGraph(graph, 'Output/PosGraphs/pos_'+str(i))
			#################
			#once graph is done, create attribute vector
			attributes = graphAttributes(graph)
			##FOR TESTING##
			#attributes = []
			#if(not nx.is_connected(graph)):
			#	print("Graph " + i + "from within is not connected")
			#	sys.exit(2)
			#else:
			#	attributes.append(nx.is_connected(graph))
			#add 1 to the end since near native
			attributes.append(1)
			#and output to file as row
			writer.writerow(attributes)
		#Negative Data Set
		for i in range(len(morethanlRMSD)):
			graph = nx.Graph()
			curr_conf = morethanlRMSD[i]
			for j in range(len(curr_conf)-RES_DISTANCE):
				for k in range(j+RES_DISTANCE, len(curr_conf)):
					atom1 = curr_conf[j]
					atom2 = curr_conf[k]
					#add nodes to graph with labels
					graph.add_node(j)
					graph.node[j]['aminoAcid'] = labels[j]
					if(labels[j] in HPHOBIC):
						graph.node[j]['hydro'] = 'phobic'
					else:
						graph.node[j]['hydro'] = 'philic'
					graph.add_node(k)
					graph.node[k]['aminoAcid'] = labels[k]
					if(labels[k] in HPHOBIC):
						graph.node[k]['hydro'] = 'phobic'
					else:
						graph.node[k]['hydro'] = 'philic'
					#find euclidean distance between atoms
					d = Distance.euclideanDistance(atom1, atom2)
					#if less than BIN_CRITERIA, add edge
					if(d <= BIN_CRITERIA):
						graph.add_edge(j, k, distance=d)
			##FOR TESTING ONLY
			#printGraph(graph, 'Output/NegGraphs/neg_'+str(i))
			#################
			#once graph is done, create attribute vector
			attributes = graphAttributes(graph)
			##FOR TESTING ONLY##
			#if(not nx.is_connected(graph)):
			#	print("Graph " + i + "from morethan is not connected")
			#	sys.exit(2)
			#else:
			#	attributes.append(nx.is_connected(graph))
			#add 0 to the end since decoy
			attributes.append(0)
			#and output to file as row
			writer.writerow(attributes)
		print("ATTRIBUTES HAVE BEEN OUTPUTTED")