How to load a structure from a .cif file?
Hi, I've just started to work up some code for my phd. I've found cctbx to be quite a nice code base for my goals. So far I've seen that there is quite a large ammount of functions implemented, but in my opinion documentation on how to use them is either hidden or not in very verbose state. So from looking at the source I'm pretty confident that cctbx can load a crystalstructure from a .cif file (like those obtained from COD, http://www.crystallography.net/). But so far I've not been able to figure out how to do this. My experiments included: from iotbx import crystal_symmetry_from_any as sym_from_any from iotbx import file_reader file_name = "./xtal_data/9008806.cif" structure = file_reader.any_file(file_name) #gives an object, but not a structure # or structure = sym_from_any.extract_from(file_name) # returns none print(str(structure)) structure.show_summary().show_scatterers() Could you give me a hint into the right direction, please? With regards, Jan Simons
2010/12/10 Jan Marten Simons
So from looking at the source I'm pretty confident that cctbx can load a crystalstructure from a .cif file (like those obtained from COD, http://www.crystallography.net/). But so far I've not been able to figure out how to do this. My experiments included:
from iotbx import crystal_symmetry_from_any as sym_from_any from iotbx import file_reader
file_name = "./xtal_data/9008806.cif" structure = file_reader.any_file(file_name) #gives an object, but not a structure # or structure = sym_from_any.extract_from(file_name) # returns none
The file_reader module is a little misleading - it was written to be used in the Phenix GUI, which is specific to macromolecular crystallography, and thus assumes that any CIF file is specifying geometry restraints. This may actually be unnecessary for what I'm doing with it, so I'm open to using a more content-neutral API for reading CIFs in iotbx.file_reader. We should have a reader for actual structures in CIF format, because this is definitely used by the small-molecule parts of CCTBX, but I'm not sure how to use it. Hopefully one of the other developers can explain. -Nat
Hi Jan,
This should be fairly straightforward:
from cctbx import xray
xs = xray.structure.from_cif(file_path="my.cif")
This will return you an instance of xray.structure. If you have more than
one data block in your cif, you can specify which structure you want to
extract using the block_heading keyword (by default it just returns the
first structure it can successfully extract from the cif). There is also
similar functionality that can be used to extract miller arrays from fcf or
hkl formats.
Please let me know if you have any further questions about this.
Cheers,
Richard
2010/12/10 Jan Marten Simons
Hi,
I've just started to work up some code for my phd. I've found cctbx to be quite a nice code base for my goals. So far I've seen that there is quite a large ammount of functions implemented, but in my opinion documentation on how to use them is either hidden or not in very verbose state.
So from looking at the source I'm pretty confident that cctbx can load a crystalstructure from a .cif file (like those obtained from COD, http://www.crystallography.net/). But so far I've not been able to figure out how to do this. My experiments included:
from iotbx import crystal_symmetry_from_any as sym_from_any from iotbx import file_reader
file_name = "./xtal_data/9008806.cif" structure = file_reader.any_file(file_name) #gives an object, but not a structure # or structure = sym_from_any.extract_from(file_name) # returns none
print(str(structure))
structure.show_summary().show_scatterers()
Could you give me a hint into the right direction, please?
With regards,
Jan Simons _______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
Am Samstag 11 Dezember 2010 14:16:37 schrieb Richard Gildea:
Hi Jan,
This should be fairly straightforward:
from cctbx import xray
xs = xray.structure.from_cif(file_path="my.cif")
From a gentoo-user pov a simple switch to the build system to use the bundled or system-wide boost/... would be very helpful here. That way gentoo developers could easily follow current cctbx releases without the need to
This looks very good. Sadly I could not yet test it here, as I'm on gentoo linux and the most recent version of cctbx there is 2010.03.29.2334 [1]. I've tried to adapt the ebuild to the most recent release, but as gentoo unbundles boost (by policy and for good reasons [2]), I'm stuck with outdated patches [3] to the SConsscripts of cctbx. patch all SConscript files. This would help Calculate linux [4] and other distributions as well, as quite a few base off from gentoo. [1] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sci-libs/cctbx/ [2] http://blog.flameeyes.eu/2009/03/23/bundling-libraries-the-curse-of-the- ancients [3] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sci- libs/cctbx/files/ [4] http://www.calculate-linux.org/packages/sci-libs/cctbx
This will return you an instance of xray.structure. If you have more than one data block in your cif, you can specify which structure you want to extract using the block_heading keyword (by default it just returns the first structure it can successfully extract from the cif). There is also similar functionality that can be used to extract miller arrays from fcf or hkl formats.
Please let me know if you have any further questions about this.
I was thinking that perhaps a user-driven wiki for examples and more detailed documentation/howtos might be a nice addition so that some practical use cases could be documented there. This might be beneficial for new users of cctbx, as at the moment the documentation seems to be very much tied to the source code, which is a rather developer oriented approach. With regards, Jan M. Simons Institute of Crystallography RWTH Aachen
Hi Jan, Did you try installing from sources? E.g. wget http://cci.lbl.gov/cctbx_build/results/2010_12_13_0000/cctbx_python_271_bund... perl cctbx_python_271_bundle.selfx Just wait a few minutes... done. You'll have the latest of everything. We don't have the resources to support specific platforms, but it shouldn't be a limitation since the source installations are extremely simple. If you need additional Python packages (e.g. numpy) simply unpack them and run "cctbx.python setup.py" to install them into the Python you got with the cctbx bundle. You can also easily use an existing Python installation to build cctbx; see the docs. Ralf ----- Original Message ----
From: Jan Marten Simons
To: cctbx mailing list Sent: Mon, December 13, 2010 5:23:09 AM Subject: Re: [cctbxbb] How to load a structure from a .cif file? Am Samstag 11 Dezember 2010 14:16:37 schrieb Richard Gildea:
Hi Jan,
This should be fairly straightforward:
from cctbx import xray
xs = xray.structure.from_cif(file_path="my.cif")
This looks very good. Sadly I could not yet test it here, as I'm on gentoo linux and the most recent version of cctbx there is 2010.03.29.2334 [1]. I've
tried to adapt the ebuild to the most recent release, but as gentoo unbundles
boost (by policy and for good reasons [2]), I'm stuck with outdated patches [3] to the SConsscripts of cctbx. From a gentoo-user pov a simple switch to the build system to use the bundled
or system-wide boost/... would be very helpful here. That way gentoo developers could easily follow current cctbx releases without the need to patch all SConscript files. This would help Calculate linux [4] and other distributions as well, as quite a few base off from gentoo.
[1] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sci-libs/cctbx/ [2] http://blog.flameeyes.eu/2009/03/23/bundling-libraries-the-curse-of-the- ancients [3] http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sci- libs/cctbx/files/ [4] ] http://www.calculate-linux.org/packages/sci-libs/cctbx
This will return you an instance of xray.structure. If you have more than one data block in your cif, you can specify which structure you want to extract using the block_heading keyword (by default it just returns the first structure it can successfully extract from the cif). There is also similar functionality that can be used to extract miller arrays from fcf or hkl formats.
Please let me know if you have any further questions about this.
I was thinking that perhaps a user-driven wiki for examples and more detailed
documentation/howtos might be a nice addition so that some practical use cases
could be documented there. This might be beneficial for new users of cctbx, as
at the moment the documentation seems to be very much tied to the source code,
which is a rather developer oriented approach.
With regards,
Jan M. Simons
Institute of Crystallography RWTH Aachen _______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
Am Samstag 11 Dezember 2010 14:16:37 schrieb Richard Gildea:
Hi Jan,
This should be fairly straightforward:
from cctbx import xray
xs = xray.structure.from_cif(file_path="my.cif")
This will return you an instance of xray.structure. If you have more than one data block in your cif, you can specify which structure you want to extract using the block_heading keyword (by default it just returns the first structure it can successfully extract from the cif). There is also similar functionality that can be used to extract miller arrays from fcf or hkl formats.
Ok, my code is now like this: file_name = "./xtal_data/9008806.cif" #file_name = "./xtal_data/9010017.cif" structure = xray.structure.from_cif(file_path=file_name) print(str(structure)) structure.show_summary().show_scatterers()
Please let me know if you have any further questions about this.
I've tested it with 2 cif files chosen at will from COD: * http://www.crystallography.net/cif/9/9010017.cif works like expected. * http://www.crystallography.net/cif/9/9008806.cif gives an error: " ./xtal_data/9008806.cif(43) : error 3 : ()* loopback of 150:8: ( ( WHITESPACE )+ ( data_items | save_frame ) )*, at offset 0 near _ : cannot match to any predicted input... Traceback (most recent call last): File "Check_F_calc.py2", line 12, in <module> structure = xray.structure.from_cif(file_path=file_name) File "/home/marten/Arbeit/cctbx- latest/cctbx_sources/cctbx/xray/structure.py", line 1366, in from_cif data_structure_builder=builders.crystal_structure_builder).structure AttributeError: 'NoneType' object has no attribute 'structure' " This either suggests an error in the .cif file or in the cif file parser of cctbx. From taking a look at both cif files I'm not sure why it breaks on the 2nd one. With regards, Jan Simons
Hi Jan,
Thanks for pointing out the problem. There is a fix now on the svn, so you
can either grab the updates off sourceforge, or for now just comment
out (with a #) the offending line (43, beginning _[local]), since this line
is of no use (to the cctbx) anyway.
Cheers,
Richard
2010/12/14 Jan Marten Simons
Am Samstag 11 Dezember 2010 14:16:37 schrieb Richard Gildea:
Hi Jan,
This should be fairly straightforward:
from cctbx import xray
xs = xray.structure.from_cif(file_path="my.cif")
This will return you an instance of xray.structure. If you have more than one data block in your cif, you can specify which structure you want to extract using the block_heading keyword (by default it just returns the first structure it can successfully extract from the cif). There is also similar functionality that can be used to extract miller arrays from fcf or hkl formats.
Ok, my code is now like this: file_name = "./xtal_data/9008806.cif" #file_name = "./xtal_data/9010017.cif" structure = xray.structure.from_cif(file_path=file_name) print(str(structure)) structure.show_summary().show_scatterers()
Please let me know if you have any further questions about this.
I've tested it with 2 cif files chosen at will from COD:
* http://www.crystallography.net/cif/9/9010017.cif works like expected.
* http://www.crystallography.net/cif/9/9008806.cif gives an error:
" ./xtal_data/9008806.cif(43) : error 3 : ()* loopback of 150:8: ( ( WHITESPACE )+ ( data_items | save_frame ) )*, at offset 0 near _ : cannot match to any predicted input...
Traceback (most recent call last): File "Check_F_calc.py2", line 12, in <module> structure = xray.structure.from_cif(file_path=file_name) File "/home/marten/Arbeit/cctbx- latest/cctbx_sources/cctbx/xray/structure.py", line 1366, in from_cif data_structure_builder=builders.crystal_structure_builder).structure AttributeError: 'NoneType' object has no attribute 'structure' "
This either suggests an error in the .cif file or in the cif file parser of cctbx. From taking a look at both cif files I'm not sure why it breaks on the 2nd one.
With regards,
Jan Simons _______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
participants (4)
-
Jan Marten Simons
-
Nat Echols
-
Ralf W. Grosse-Kunstleve
-
Richard Gildea