Example #1
0
class TestLattice(unittest.TestCase):
    def setUp(self):
        a, b, c = 4, 5, 6
        alpha, beta, gamma = 90., 90.0, 90.0
        self.lattice = Lattice(a, b, c, alpha, beta, gamma)

    def test_volume(self):
        """docstring for test_volume"""
        self.assertEqual(self.lattice.volume, 4 * 5 * 6.0)

    def test_distance(self):
        """docstring for test_volume"""
        abc1 = [0.2, 0.35, 0.45]
        abc2 = [0.1, 0.15, 0.15]
        d = self.lattice.distance(abc1, abc2)
        print d

    def test_convert_to_xyz(self):
        """docstring for test_volume"""
        abc = [0.2, 0.35, 0.45]
        xyz = self.lattice.fractionalize(abc)
        print xyz

    def test_convert_to_abc(self):
        """docstring for test_volume"""
        xyz = [1.2, 1.35, 2.45]
        abc = self.lattice.orthogonalize(xyz)
        print abc
Example #2
0
class TestLattice(unittest.TestCase):
    def setUp(self):
        a,b,c = 4,5,6
        alpha,beta,gamma = 90., 90.0, 90.0
        self.lattice =  Lattice(a,b,c,alpha,beta,gamma)
        
    def test_volume(self):
        """docstring for test_volume"""
        self.assertEqual(self.lattice.volume, 4*5*6.0)

    def test_distance(self):
        """docstring for test_volume"""
        abc1 = [0.2, 0.35, 0.45]
        abc2 = [0.1, 0.15, 0.15]
        d = self.lattice.distance(abc1,abc2)
        print d

    def test_convert_to_xyz(self):
        """docstring for test_volume"""
        abc = [0.2, 0.35, 0.45]
        xyz = self.lattice.fractionalize(abc)
        print xyz

    def test_convert_to_abc(self):
        """docstring for test_volume"""
        xyz = [1.2, 1.35, 2.45]
        abc = self.lattice.orthogonalize(xyz)
        print abc
Example #3
0
 def load_from_xdict(args):
     """
     Create a crystal object from a dictionary.
     
     The input dictionary must have all used fields or key errors will result.
     """
     #print args
     sites = [
         Site(label=a['name'], abc=a['abc'], occupancy=a['occupancy'])
         for a in args['sites']
     ]
     # Lattice and SpaceGroup could be initialized from dict or Lattice/SpaceGroup objects
     # right not crystal is initialized by dict
     lattice = Lattice(args['lattice']['a'], args['lattice']['b'],
                       args['lattice']['c'], args['lattice']['alpha'],
                       args['lattice']['beta'], args['lattice']['gamma'])
     # self.cctbx_name = args["space_group"]["cctbx_name"]
     # name should be of the type : "P m m n :2"
     cctbx_name = args['space_group']['cctbx_name']
     space_group = SpaceGroup(cctbx_name)
     # necessary data from db
     transforms = args.get('transforms', [])
     crystal = Crystal(sites=sites,
                       lattice=lattice,
                       space_group=space_group,
                       transforms=transforms)
     return crystal
Example #4
0
 def test_symmetry_error(self):
     space_group = SpaceGroup('F d d 2')
     lattice = Lattice(4.0, 5.0, 6.0, 88.0, 91.0, 95.0)
     sites = []
     sites.append(Site(label="Li", abc=(0.25, 0.0, 0.0), occupancy=0.80))
     #crystal = Crystal(sites=sites, space_group=space_group, lattice=lattice)
     pass
Example #5
0
    def __init__(self,
                 space_group=SpaceGroup('P 1'),
                 lattice=Lattice(1.0, 1.0, 1.0, 90.0, 90.0, 90.0),
                 sites=[]):
        """
        Crystal object.
        Functions as a wrapper to a cctbx xray.structure object,
        but adds additional variables and functionality.
        Core object of this package.
        
        Input:
            SpaceGroup  space_group                            space group for the current crystal
            List of Site objects  sites                        List of Site objects.
        
        Warning:
            'crystal_structure' must be given,
            or 'space_group', 'lattice', and 'sites' must be given,
            or creation of the crystal will fail.
        """

        try:
            crystal_symmetry = crystal.symmetry(
                unit_cell=str(lattice),
                space_group_symbol=space_group.cctbx_name)
        except Exception as e:
            raise SymmetryError(
                "SpaceGroup {s} is incompatible with Lattice -> {l} cctbx error {e}"
                .format(l=str(lattice), s=SpaceGroup.cctbx_name, e=e))

        scatterers = flex.xray_scatterer()
        for i, site in enumerate(sites):
            # the element name can be pulled from scatterer via the s.element_symbol() method (if it's an element!!!)
            # example: 'atom-b-12',or 'vacancy-c-3'
            # we need to set the scattering_type so we can freely use the label to store metadata

            #scattering_type = something
            #scatterers.append(xray.scatterer(label=atom.name, site=tuple(atom.abc), occupancy=atom.occupancy), scattering_type=atom.name)

            #Method #2
            # explicitly add metadata to _meta
            st_temp, dash, num = site.label.partition("-")
            if dash == "-":
                k = site.label
            else:
                k = "-".join([site.label, str(i)])

            # problems here not sure what's up
            k = str(k)
            # print "label = ", k, ' type of label = ', type(k)
            # print "site = ", tuple(site.abc)
            # print "occupancy = ", site.occupancy
            scatterers.append(
                xray.scatterer(label=k,
                               site=tuple(site.abc),
                               occupancy=site.occupancy))

        # Test for coherency of Lattice and SpaceGroup
        self.crystal_structure = xray.structure(
            crystal_symmetry=crystal_symmetry, scatterers=scatterers)
Example #6
0
 def setUp(self):
     self.cif_file_names = [
         os.path.abspath(file_name)
         for file_name in glob.glob(os.path.join(TEST_FILES, 'cifs/*.cif'))
     ]
     space_group = SpaceGroup('C 1 2/m 1')
     lattice = Lattice(4.0, 5.0, 6.0, 90.0, 109.10, 90.0)
     sites = []
     sites.append(Site(label="Li", abc=(0.25, 0.0, 0.0), occupancy=0.80))
     sites.append(Site(label="Mn", abc=(0.25, 0.0, 0.0), occupancy=0.20))
     sites.append(Site(label="O", abc=(0.5, 0.5, 0.5)))
     self.crystal = Crystal(sites=sites,
                            space_group=space_group,
                            lattice=lattice)
Example #7
0
 def get_lattice(self):
     """ Return the a copy of the crystal lattice as a Lattice object. """
     p = self.crystal_structure.unit_cell().parameters()
     return Lattice(p[0], p[1], p[2], p[3], p[4], p[5])
Example #8
0
 def setUp(self):
     a, b, c = 4, 5, 6
     alpha, beta, gamma = 90., 90.0, 90.0
     self.lattice = Lattice(a, b, c, alpha, beta, gamma)
Example #9
0
 def setUp(self):
     a,b,c = 4,5,6
     alpha,beta,gamma = 90., 90.0, 90.0
     self.lattice =  Lattice(a,b,c,alpha,beta,gamma)