def test_get_nameless_cuds_component(self): c = CUDS() c.add([self.nameless_cuds_1]) component = c.get(self.nameless_cuds_1.uid) self.assertEqual(component, self.nameless_cuds_1) self.assertRaises(TypeError, c.get_by_name, component.name)
def test_get_named_cuds_component(self): c = CUDS() c.add([self.named_cuds_1]) self.assertEqual(c.get_by_name(self.named_cuds_1.name), self.named_cuds_1) self.assertEqual(c.get(self.named_cuds_1.uid), self.named_cuds_1)
def test_add_nameless_cuds_component(self): c = CUDS() c.add([self.nameless_cuds_1]) self.assertEqual(c.get(self.nameless_cuds_1.uid), self.nameless_cuds_1) self.assertRaises(TypeError, c.get_by_name, self.nameless_cuds_1.name)
def test_add_nameless_component_several_times(self): c = CUDS() c.add([self.nameless_cuds_1]) c.add([self.nameless_cuds_1]) component = c.get(self.nameless_cuds_1.uid) self.assertEqual(component, self.nameless_cuds_1) self.assertRaises(TypeError, c.get_by_name, component.name)
def test_cuds_update(self): component = api.Box(name='a box') c = CUDS() c.add([component]) component.name = 'updated box' c.update([component]) updated_component = c.get(component.uid) self.assertEqual(updated_component.name, 'updated box')
def read_data_file(filename, atom_style=None, name=None): """ Reads LAMMPS data file and create CUDS objects Reads LAMMPS data file and create a Particles and CUDS. The CUDS will contain a material for each atom type (e.g. CUBA.MATERIAL_TYPE). The attributes for each particle are based upon what atom-style the file contains (i.e. "sphere" means that particles in addition to having CUBA.VELOCITY will also have a CUBA.RADIUS and CUBA.MASS). See 'atom_style' for more details. Parameters ---------- filename : str filename of lammps data file atom_style : AtomStyle, optional type of atoms in the file. If None, then an attempt of interpreting the atom-style in the file is performed. name : str, optional name to be given to returned Particles. If None, then filename is used. Returns ------- particles : Particles particles SD : CUDS SD containing materials """ handler = LammpsSimpleDataHandler() parser = LammpsDataFileParser(handler=handler) parser.parse(filename) if atom_style is None: atom_style = ( get_atom_style(handler.get_atom_type()) if handler.get_atom_type() else AtomStyle.ATOMIC) types = (atom_t for atom_t in range(1, handler.get_number_atom_types() + 1)) atoms = handler.get_atoms() velocities = handler.get_velocities() masses = handler.get_masses() box_origin = handler.get_box_origin() box_vectors = handler.get_box_vectors() type_to_material_map = {} statedata = CUDS() # set up a Material for each different type for atom_type in types: material = Material() description = "Material for lammps atom type (originally '{}')".format( atom_type ) material.description = description type_to_material_map[atom_type] = material.uid statedata.add([material]) # add masses to materials for atom_type, mass in masses.iteritems(): material = statedata.get(type_to_material_map[atom_type]) material.data[CUBA.MASS] = mass statedata.update([material]) def convert_atom_type_to_material(atom_type): return type_to_material_map[atom_type] interpreter = LammpsDataLineInterpreter(atom_style, convert_atom_type_to_material) # create particles particles = Particles(name=name if name else filename) data = particles.data data.update({CUBA.ORIGIN: box_origin, CUBA.VECTOR: box_vectors}) particles.data = data # add each particle for lammps_id, values in atoms.iteritems(): coordinates, data = interpreter.convert_atom_values(values) data.update(interpreter.convert_velocity_values(velocities[lammps_id])) p = Particle(coordinates=coordinates, data=data) particles.add([p]) return particles, statedata