def read_xyz_charge_mult(file):
	"""
	Reads charge and multiplicity from XYZ files. These parameters should be defined
	in the title lines as charge=X and mult=Y (i.e. FILENAME charge=1 mult=1 Eopt -129384.564)
	"""

	charge_xyz,mult_xyz = None,None
	# read charge and mult from xyz files
	with open(file, "r") as F:
		lines = F.readlines()
	for line in lines:
		for keyword in line.strip().split():
			if keyword.lower().find('charge') > -1:
				charge_xyz = int(keyword.split('=')[1])
			elif keyword.lower().find('mult') > -1:
				mult_xyz = int(keyword.split('=')[1])
			elif charge_xyz is not None and mult_xyz is not None:
				break

	if charge_xyz is None:
		charge_xyz = 0
	if mult_xyz is None:
		mult_xyz = 1

	return charge_xyz,mult_xyz