def open_cif(param, phase): """ Open a cif file a build a structure for phase number "phase" filename: param['structure_phase_%i' %phase] returns - a structure with cif information sets - param['sgno_phase_%i' %phase] : space group number - param['sgname_phase_%i' %phase] : space group name - param['cell_choice_phase_%i' %phase] : not 100% sure - param['unit_cell_phase_%i' %phase] : unit cell parameters as [a,b,c,alpha,beta,gamma'] Adapted from polyxsim.structure Created: 12/2019, S. Merkel, Univ. Lille, France """ file = param['structure_phase_%i' % phase] cf = ReadCif( file ) # Generate an error if reading cif fails which is not always true below struct = structure.build_atomlist() struct.CIFread(ciffile=file) param['sgno_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).no param['sgname_phase_%i' % phase] = struct.atomlist.sgname param['cell_choice_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).cell_choice param['unit_cell_phase_%i' % phase] = struct.atomlist.cell return struct
def open_structure(param, phase): file = param['structure_phase_%i' % phase] if file[-3:] == 'cif': if ('structure_datablock_phase_%i' % phase) in param: datablock = param['structure_datablock_phase_%i' % phase] else: datablock = None struct = structure.build_atomlist() struct.CIFread(ciffile=file, cifblkname=datablock) elif file[-3:] == 'pdb': struct = structure.build_atomlist() struct.PDBread(pdbfile=file) else: raise IOError('Unknown structure file format') param['sgno_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).no param['sgname_phase_%i' % phase] = struct.atomlist.sgname param['cell_choice_phase_%i' % phase] = sg.sg(sgname=struct.atomlist.sgname).cell_choice param['unit_cell_phase_%i' % phase] = struct.atomlist.cell return struct
def test_sfcalc(self): ## test method names begin 'test*' # Read the cif mylist = structure.build_atomlist() mylist.CIFread('PPA.cif','oPPA') # Read the fcf fcf = ReadCif('oPPA.fcf')['oPPA'] for i in range(500):# Consider only the first 500 reflections hkl =[eval(fcf['_refln_index_h'][i]), eval(fcf['_refln_index_k'][i]), eval(fcf['_refln_index_l'][i])] (Fr, Fi) = structure.StructureFactor(hkl, mylist.atomlist.cell, mylist.atomlist.sgname, mylist.atomlist.atom, mylist.atomlist.dispersion) F2 = Fr**2 + Fi**2 reldif = F2/eval(fcf['_refln_F_squared_calc'][i])-1 print(i, reldif, F2) if F2 > 10: # Only compare those with an F^2 larger than ten # to avoid that the very weak reflections which # have a relative difference that are slightly larger self.assertAlmostEqual(reldif,0,2)
def test_cifread(self): mylist = structure.build_atomlist() mylist.CIFread('PPA.cif','oPPA') self.assertEqual([8.5312,4.8321,10.125,90.00,92.031,90.00], mylist.atomlist.cell)
def test_cifopen(self): ## test method names begin 'test*' mylist = structure.build_atomlist() mylist.CIFopen('PPA.cif','oPPA')