Package: shelxfile
ShelxfileThis is a full implementation of the SHELXL[1] file syntax. Additionally it is able to edit SHELX properties using Python.
The implementation is Python3-only and supports SHELXL after 2017 (You should not use old versions anyway).
Shelxfile may eventually become a new heart of DSR[2] and is already used as file parser in StructureFinder[3].Shelxfile always keeps the file order intact. Every SHELX instruction like DFIX or an atom is stored as an class object in the list Shelxfile._reslist. When writing the Shelxfile content to disk, it wites the _reslist content to disk.Shelxfile tries to detect all possible syntax errors that SHELXL would not like either. If Shelxfile.DEBUG is True, more output about syntax and other errors are printed out. Otherwise, the parser is quiet except for really severe errors like a missing unit cell.Not every part of Shelxfile is complete, for example it will not recognize if you add restraints with atom names that are not in the SHELX file. Please help me improving it!Source CodeYou can find the ShelXfile source code at GitHub.Examples:pipinstallshelxfile>>>fromshelxfileimportShelxfile>>>shx=Shelxfile(verbose=True)# or debug=True, debug will halt on errors.>>>shx.read_file('src/tests/resources/p21c.res')# or .read_string()>>>shx.cellCELL0.7107310.508620.903520.50729094.1390>>>list(shx.cell)[10.5086,20.9035,20.5072,90.0,94.13,90.0]>>>shx.cell.volume4493.047384590458>>>shx.cell.a10.5086>>>shx.to_cif('test.cif')# Writes a CIF file from the content of p21c.res# You can overwrite any parameter in a shelx file:>>>shx.planPLAN20>>>shx.plan.npeaks20>>>shx.plan.set('PLAN 30')>>>shx.planPLAN30>>>shx.atomsO130.0748350.2384360.402457-31.000000.015790.030950.01852-0.00468-0.002100.01153C110.0285760.2345420.337234-31.000000.023110.036170.01096-0.010000.002010.00356C210.1215400.1944600.298291-31.000000.029600.045860.01555-0.00485-0.000230.01102F...>>>shx.atoms.hydrogen_atoms[AtomID:81,AtomID:88,AtomID:95,...]>>>shx.atoms.hydrogen_atoms[1].name'H32'>>>shx.atoms.n_hydrogen_atoms24# Atoms with a riding model e.g. hydrogen atom riding on a carbon atom:>>>shx.atoms.riding_atoms[AtomID:81,AtomID:88,AtomID:95,...]>>>a=shx.atoms.get_atom_by_name('F1_2')# Atom F1 in residue 2>>>aAtomID:258# <- The Atom ID is the index number in the Shelxfile._reslist list>>>str(a)'F1    4    0.245205    0.192674    0.649231   -21.00000    0.05143    0.03826    0.03193   -0.00579   -0.01865   -0.00485'>>>a.to_isotropic()>>>str(a)'F1    4    0.245205    0.192674   0.649231  -21.00000    0.04000'>>>a.position# position in the SHELX .res file273>>>str(shx._reslist[273])# In regular code, do not access shx._reslist directly!'F1    4    0.245205    0.192674   0.649231  -21.00000    0.04000'>>>a.name'F1'>>>a.element'F'# Introduce a new element>>>a.element='Na'>>>shx.sfac_tableSFACCHOFAlGaNa>>>a.resinum2>>>a.part2>>>shx.sfac2elem(4)'F'>>>shx.elem2sfac('F')4>>>a.find_atoms_around(dist=2.0,only_part=1)[AtomID:254,AtomID:256,AtomID:260]# Found some atoms>>>[str(x)forxina.find_atoms_around(dist=2.2,only_part=2)]['C2     1    0.192984    0.140449    0.621265   -21.00000    0.04315    0.02747      0.02385    0.00686   -0.00757    0.00126','F2     4    0.264027    0.090306    0.642441   -21.00000    0.06073    0.04450      0.03972    0.01630   -0.01260    0.01460','F3     4    0.078582    0.131920    0.643529   -21.00000    0.05691    0.04955      0.03374    0.01040    0.01881    0.00375']>>>a.cart_coords[1.617897551082389,4.027560959000001,13.279336538026433]>>>a.frac_coords[0.245205,0.192674,0.649231]>>>a.occupancy1.0>>>a.sfac_num4>>>[xforxina.find_atoms_around(dist=2.5,only_part=2)][AtomID:254,AtomID:256,AtomID:260,AtomID:262]>>>forxina.find_atoms_around(dist=2.5,only_part=2):...x.delete()>>>[xforxina.find_atoms_around(dist=2.5,only_part=2)][]# Atoms are now deleted from shx._reslist.>>>shx.restraintsSADI_CCF30.02C1C2C1C3C1C4SADI_CCF30.02F1C2F2C2F3C2F4C3F5C3F6C3F7C4F8C4F9C4SADI_CCF30.04C2C3C3C4C2C4SADI_CCF30.04O1C2O1C3O1C4SADI_CCF30.04F1F2F2F3F3F1F4F5F5F6F6F4F7F8F8F9F9F7...>>>shx.restraints[1]SADI_CCF30.02C1C2C1C3C1C4str(shx.restraints[1])'SADI_CCF3 0.02 C1 C2 C1 C3 C1 C4'shx.restraints[1].residue_class'CCF3'# The residue class 'CCF3' has three residues with these numbers:>>>shx.restraints[1].residue_number[4,1,2]# The esd of the SADI restraint:shx.restraints[1].s0.02Writes current shx object to test.ins
All lines in Shelxfile._reslist get wrapped after 79 characters with " =\n " as
specified by SHELXL during the file writing.>>>shx.write_shelx_file('test.ins')No matter if you loaded a .res or .ins file with refine(), SHELXL refines the structure of the Shelxfile() object:>>>shx.insert_anis()>>>shx.refine(2)RunningSHELXLwith"/usr/local/bin/shelxl -b3000 /Users/daniel/GitHub/Shelxfile/tests/p21c"and"L.S. 2"wR2=0.1143beforecycle1for10786dataand945/945parameterswR2=0.1025beforecycle2for10786dataand945/945parameterswR2=0.1006beforecycle3for10786dataand0/945parametersSHELXLVersion2018/3# Symmcards that are implied by lattice symmetry are generated on-the-fly:>>>shx.symmcards|100||0.0||010|+|0.0||001||0.0||-100||0.0||0-10|+|0.0||00-1||0.0||-100||0.0||010|+|0.5||00-1||0.5||100||0.0||0-10|+|-0.5||001||-0.5|# Complete or "grow" structures with higher symmetry:>>>shx=Shelxfile('./tests/p-31c.res')len(shx.atoms)88p=shx.grow()len(p)208# The (bond) angle between three atoms:>>>at1=shx.atoms.get_atom_by_name('O1_4')>>>at2=shx.atoms.get_atom_by_name('C1_4')>>>at3=shx.atoms.get_atom_by_name('C2_4')>>>shx.atoms.angle(at1,at2,at3)109.688123# The torsion angle between four atoms:>>>at1=shx.atoms.get_atom_by_name('O1')>>>at2=shx.atoms.get_atom_by_name('C1')>>>at3=shx.atoms.get_atom_by_name('C2')>>>at4=shx.atoms.get_atom_by_name('F1')>>>shx.atoms.torsion_angle(at1,at2,at3,at4)74.095731and many more...References[1]http://shelx.uni-goettingen.de/, G. M. Sheldrick, Acta Cryst. (2015). C71, 3-8.https://doi.org/10.1107/S2053229614024218[2]https://github.com/dkratzert/DSR[3]https://github.com/dkratzert/StructureFinder