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
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
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)
def space_group(self): """ Return the space group of the crystal. """ sgt = self.crystal_structure.space_group().type() symbol = sgt.lookup_symbol() name = '' if re.search(r'\(', symbol): name = symbol.split("(")[0].rstrip() else: name = symbol return SpaceGroup(name)
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)
def from_crystal_structure(crystal_structure): c = Crystal(space_group=SpaceGroup('P1')) c.crystal_structure = crystal_structure return c
def setUp(self): """docstring for setUp""" cctbx_names = ["P m m n :1", "P 1", "C 1 2/m 1"] self.space_groups = [SpaceGroup(name) for name in cctbx_names]