def test_from_vector_with_label(self): vector = [2, 3, 1] label = 'A' so = SymmetryOperation.from_vector(vector, label=label) np.testing.assert_array_equal( so.matrix, np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]])) self.assertEqual(so.label, label)
def read_from_file_with_labels(cls, filename): """ Create a :any:`SymmetryGroup` object from a file, with labelled symmetry operations. The file format should be a series of numerical mappings representing each symmetry operation, prepended with a string that will be used as a label. e.g. for a pair of equivalent sites:: # example input file to define the spacegroup for a pair of equivalent sites E 1 2 C2 2 1 Args: filename (str): Name of the file to be read in. Returns: spacegroup (SymmetryGroup) """ data = np.genfromtxt(filename, dtype=str) labels = [row[0] for row in data] vectors = [[float(s) for s in row[1:]] for row in data] symmetry_operations = [ SymmetryOperation.from_vector(v) for v in vectors ] [so.set_label(l) for (l, so) in zip(labels, symmetry_operations)] return (cls(symmetry_operations=symmetry_operations))
def space_group_from_structure( structure, subset=None, atol=1e-5 ): """ Generates a ``SpaceGroup`` object from a `pymatgen` ``Structure``. Args: structure (pymatgen ``Structure``): structure to be used to define the :any:`SpaceGroup`. subset (Optional [list]): list of atom indices to be used for generating the symmetry operations. atol (Optional [float]): tolerance factor for the ``pymatgen`` `coordinate mapping`_ under each symmetry operation. Returns: a new :any:`SpaceGroup` instance .. _coordinate mapping: http://pymatgen.org/pymatgen.util.coord_utils.html#pymatgen.util.coord_utils.coord_list_mapping_pbc """ mappings = unique_symmetry_operations_as_vectors_from_structure( structure, subset=subset, atol=atol ) symmetry_operations = [ SymmetryOperation.from_vector( m ) for m in mappings ] return SpaceGroup( symmetry_operations=symmetry_operations )
def point_group_from_molecule( molecule, subset=None, atol=1e-5 ): """ Generates a ``PointGroup`` object from a `pymatgen` ``Molecule``. Args: molecule (pymatgen ``Molecule``): molecule to be used to define the :any:`PointGroup`. subset (Optional [list]): list of atom indices to be used for generating the symmetry operations. atol (Optional [float]): tolerance factor for the ``pymatgen`` `coordinate mapping`_ under each symmetry operation. Returns: a new :any:`PointGroup` instance .. _coordinate mapping: http://pymatgen.org/pymatgen.util.coord_utils.html#pymatgen.util.coord_utils.coord_list_mapping """ molecule = Molecule( molecule.species, molecule.cart_coords - molecule.center_of_mass ) mappings = unique_symmetry_operations_as_vectors_from_structure( molecule, subset=subset, atol=atol ) symmetry_operations = [ SymmetryOperation.from_vector( m ) for m in mappings ] return PointGroup( symmetry_operations=symmetry_operations )
def space_group_from_structure(structure, subset=None, atol=1e-5): """ Generates a ``SpaceGroup`` object from a `pymatgen` ``Structure``. Args: structure (pymatgen ``Structure``): structure to be used to define the :any:`SpaceGroup`. subset (Optional [list]): list of atom indices to be used for generating the symmetry operations. atol (Optional [float]): tolerance factor for the ``pymatgen`` `coordinate mapping`_ under each symmetry operation. Returns: a new :any:`SpaceGroup` instance .. _coordinate mapping: http://pymatgen.org/pymatgen.util.coord_utils.html#pymatgen.util.coord_utils.coord_list_mapping_pbc """ mappings = unique_symmetry_operations_as_vectors_from_structure( structure, subset=subset, atol=atol) symmetry_operations = [SymmetryOperation.from_vector(m) for m in mappings] return SpaceGroup(symmetry_operations=symmetry_operations)
def read_from_file( cls, filename ): """ Create a :any:`SymmetryGroup` object from a file. The file format should be a series of numerical mappings representing each symmetry operation. e.g. for a pair of equivalent sites:: # example input file to define the spacegroup for a pair of equivalent sites 1 2 2 1 Args: filename (str): Name of the file to be read in. Returns: spacegroup (SymmetryGroup) """ data = np.loadtxt( filename, dtype=int ) symmetry_operations = [ SymmetryOperation.from_vector( row.tolist() ) for row in data ] return( cls( symmetry_operations = symmetry_operations ) )
def point_group_from_molecule(molecule, subset=None, atol=1e-5): """ Generates a ``PointGroup`` object from a `pymatgen` ``Molecule``. Args: molecule (pymatgen ``Molecule``): molecule to be used to define the :any:`PointGroup`. subset (Optional [list]): list of atom indices to be used for generating the symmetry operations. atol (Optional [float]): tolerance factor for the ``pymatgen`` `coordinate mapping`_ under each symmetry operation. Returns: a new :any:`PointGroup` instance .. _coordinate mapping: http://pymatgen.org/pymatgen.util.coord_utils.html#pymatgen.util.coord_utils.coord_list_mapping """ molecule = Molecule(molecule.species, molecule.cart_coords - molecule.center_of_mass) mappings = unique_symmetry_operations_as_vectors_from_structure( molecule, subset=subset, atol=atol) symmetry_operations = [SymmetryOperation.from_vector(m) for m in mappings] return PointGroup(symmetry_operations=symmetry_operations)
def read_from_file(cls, filename): """ Create a :any:`SymmetryGroup` object from a file. The file format should be a series of numerical mappings representing each symmetry operation. e.g. for a pair of equivalent sites:: # example input file to define the spacegroup for a pair of equivalent sites 1 2 2 1 Args: filename (str): Name of the file to be read in. Returns: spacegroup (SymmetryGroup) """ data = np.loadtxt(filename, dtype=int) symmetry_operations = [ SymmetryOperation.from_vector(row.tolist()) for row in data ] return (cls(symmetry_operations=symmetry_operations))
def read_from_file_with_labels( cls, filename ): """ Create a :any:`SymmetryGroup` object from a file, with labelled symmetry operations. The file format should be a series of numerical mappings representing each symmetry operation, prepended with a string that will be used as a label. e.g. for a pair of equivalent sites:: # example input file to define the spacegroup for a pair of equivalent sites E 1 2 C2 2 1 Args: filename (str): Name of the file to be read in. Returns: spacegroup (SymmetryGroup) """ data = np.genfromtxt( filename, dtype=str ) labels = [ row[0] for row in data ] vectors = [ [ float(s) for s in row[1:] ] for row in data ] symmetry_operations = [ SymmetryOperation.from_vector( v ) for v in vectors ] [ so.set_label( l ) for (l, so) in zip( labels, symmetry_operations ) ] return( cls( symmetry_operations=symmetry_operations ) )
def test_from_vector_counting_from_zero( self ): vector = [ 1, 2, 0 ] so = SymmetryOperation.from_vector( vector, count_from_zero=True ) np.testing.assert_array_equal( so.matrix, np.array( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) )
def test_from_vector_with_label( self ): vector = [ 2, 3, 1 ] label = 'A' so = SymmetryOperation.from_vector( vector, label=label ) np.testing.assert_array_equal( so.matrix, np.array( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) ) self.assertEqual( so.label, label )
def test_from_vector( self ): vector = [ 2, 3, 1 ] so = SymmetryOperation.from_vector( vector ) np.testing.assert_array_equal( so.matrix, np.array( [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] ) )
def test_mul_raises_TypeError_with_invalid_type( self ): so = SymmetryOperation.from_vector( [ 2, 3, 1 ] ) with self.assertRaises( TypeError ): new_conf = so * 'foo'
def test_mul_with_configuration( self ): so = SymmetryOperation.from_vector( [ 2, 3, 1 ] ) conf = Configuration( [ 1, 2, 3 ] ) new_conf = so * conf self.assertEqual( type( new_conf ), Configuration ) self.assertEqual( new_conf.matches( Configuration( [ 3, 1, 2 ] ) ), True )
def test_mul_with_configuration(self): so = SymmetryOperation.from_vector([2, 3, 1]) conf = Configuration([1, 2, 3]) new_conf = so * conf self.assertEqual(type(new_conf), Configuration) self.assertEqual(new_conf.matches(Configuration([3, 1, 2])), True)
def test_mul_raises_TypeError_with_invalid_type(self): so = SymmetryOperation.from_vector([2, 3, 1]) with self.assertRaises(TypeError): new_conf = so * 'foo'
def test_from_vector(self): vector = [2, 3, 1] so = SymmetryOperation.from_vector(vector) np.testing.assert_array_equal( so.matrix, np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]))
def test_from_vector_counting_from_zero(self): vector = [1, 2, 0] so = SymmetryOperation.from_vector(vector, count_from_zero=True) np.testing.assert_array_equal( so.matrix, np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]))