def removed_spurious_interactions(self, data_name, sp_type):
		''' Check if no sp_type species are present in given interaction '''

		# data_name - name of the .data file section e.g. Bonds, Angles
		# sp_type - type name (string name as defined in Masses, e.g. Na)
		# Returns True if sp_type not present in any interaction 

		# Get the target .data section
		with open(self.data_file, 'r') as fin:
			data = ed.extract_data_section(fin, data_name)

		for line in data:
			line = line.strip().split()
			
			# Find the begining of atom tag list 
			# Take the n entries
			atom_ind = line.index('#') + 1

			# Check each atom - ind serves to 
			# simultaneously navigate through atom IDs
			atom_list = line[atom_ind:]

			# False if interaction includes the spurious type 
			if str(sp_type) in atom_list:
				return False

		return True
	def __init__(self, data_file, params_file, type_map={}):
		''' Loads Atoms section from the .data file ''' 
		
		# data_file, params_file - LAMMPS .data and .params file

		BaseCheck.__init__(self, data_file, params_file, type_map)

		with open(self.data_file, 'r') as fin:
			self.atoms = ed.extract_data_section(fin, 'Atoms')
	def correct_interaction_components(self, data_name):
		''' Check if atom types that constitute interaction
				tag match atom IDs in the interaction entry '''

		# data_name - name of the .data file section e.g. Bonds, Angles
		#
		# Returns True if all atom IDs in interactions entry match the
		# nominal IDs according to interaction tags

		# Get the target .data section and the Atoms section
		with open(self.data_file, 'r') as fin:
			data = ed.extract_data_section(fin, data_name)
		with open(self.data_file, 'r') as fin:
			all_atoms_data = ed.extract_data_section(fin, 'Atoms')

		# Compare
		for line in data:
			line = line.strip().split()
			# Find the begining of atom tag list 
			atom_ind = line.index('#') + 1

			# Check each atom - ind serves to 
			# simultaneously navigate through atom IDs
			# range accounts for # character
			atom_list = ' '.join(line[atom_ind:]).split(',')
			for ind, atom in zip(range(2, atom_ind - 1), atom_list):
				# Remove any whitespace
				atom.replace(' ', '')
				
				# Fetch this atom's type ID from Atoms list, assumes IDs 
				# i.e. first column in Atoms data, are sequential
				atom_type_ID = int(all_atoms_data[int(line[ind])-1].strip().split()[2])
				
				# Test if the same IDs 
				if not (int(self.atom_IDs[atom]) == atom_type_ID):
					return False

		return True
Example #4
0
    def column_number_test(self):
        ''' Check if all lines in data have expected number of columns '''

        for section_name, num_col in self.section_info:

            # Get all data for this section
            with open(self.data_file, 'r') as fin:
                data = ed.extract_data_section(fin, section_name)

            # Compare number of columns
            for line in data:
                line = line.strip().split()
                if not (len(line) == num_col):
                    return False

        return True
Example #5
0
    def missing_entries_test(self):
        ''' Check if there are any missing data points '''
        # Missing data points are signified by None or False
        # entries

        for section_name, num_col in self.section_info:

            # Get all data for this section
            with open(self.data_file, 'r') as fin:
                data = ed.extract_data_section(fin, section_name)

            # Check for missing values
            for line in data:
                line = line.strip().split()
                if 'None' in line or 'False' in line:
                    return False

        return True
	def correct_interaction_type(self, data_name, params_name):
		''' Compare tags and IDs in .param and .data files for given 
				interaction type to check if they match'''
		
		# data_name - name of the .data file section e.g. Bonds, Angles
		# params_name - name of the .params file section; section is
		#	distinguished by the actual coefficient name present in 
		#	each line that defines it e.g. bond_coeff, angle_coeff
		# 
		# Returns True if tags are equal and IDs correspond to one
		# another

		# Get the .data section
		with open(self.data_file, 'r') as fin:
			data = ed.extract_data_section(fin, data_name)

		# Get the .params section as a tag : ID dictionary
		with open(self.params_file, 'r') as fin:
			params = ed.extract_params_dict(fin, params_name)

		# Compare - this also assumes that elements in the tags
		# have the same order i.e. c,f and not f,c
		for line in data:
			line = line.strip().split()

			# Find the begining of atom list 
			ind = line.index('#') + 1
			
			if self.type_map:
				atoms = line[ind:][0].strip().split(',')
				atoms = [self.type_map[x] for x in atoms]  
				tag = tuple(atoms)
			else:
				# The prepare the tag to be just a list of atoms
				tag = tuple(' '.join(line[ind:]).strip().split(','))
			# Now compare the tags and IDs
			if not (params[tag] == int(line[1])):
				return False

		return True
	def __init__(self, data_file, params_file, type_map):
		''' Creates a dict of atom tags : atom IDs '''
			
		# data_file, params_file - LAMMPS .data and .params
		# files respectively
		# type_map - conversion rules for atom types that have 
		#		multiple represenations (like Os and o=)
		# Currently converting only parameters file

		self.data_file = data_file
		self.params_file = params_file
		self.type_map = type_map

		self.atom_IDs = {}
		# Get the data from Masses section
		with open(self.data_file, 'r') as fin:
			atom_data = ed.extract_data_section(fin, 'Masses')
		
		# Make an atom tag : atom ID dictionary
		for atom in atom_data:
			atom = atom.strip().split()
			# Assumes space between # and the tag
			self.atom_IDs[atom[-1]] = atom[0]