Discussion List Archives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Announcing PyCifRW: Simple python CIF interface

  • Subject: Announcing PyCifRW: Simple python CIF interface
  • From: James Hester <jrh@xxxxxxxxxxxx>
  • Date: Tue, 9 Oct 2001 09:37:05 +0100 (BST)
Below is an announcement about the above package.  If anyone has any
comments or suggestions, I'd be glad to hear them.

Description
-----------

PyCifRW provides the basic commands for enabling python programs to
read and write CIF files.  It is under active development and battle
testing at the Australian Beamline in Tsukuba, Japan.

Implementation
--------------

CIF input:

The draft BNC grammar was implemented using the kjParse module to
interpret the formal grammar description, with whitespace handling
moved to the lexer stage.  This means that the module is closely
conformant with the specification.  It also means that, as the parsing
is done in python, a 500K CIF file takes a minute or so to load on a
300MHz computer (the second line in the example below).  The module
passes or fails all the IUCr trap tests as required.

CIF output: 

Few checks, eg of block and data name characters, are implemented.
The output cif will conform to the grammar (including length) provided
the datanames are properly constructed.

Downloading
-----------

All the necessary files are available for downloading by anonymous ftp
from the ANBF:

ftp://anbf2.kek.jp/pub/cif/PyCifRW.tar

A new web page is also available with slightly more information (this
page will be expanded over the next few months).

http://www.ansto.gov.au/natfac/ANBF/CIF/

Documentation is still rather sparse.

Example
-------

The interface is (to me at least) the obvious way to implement CIF
reading in Python.  A CIF file is a dictionary, with each key being a
block name, and each value being a CIF block represented as another
dictionary.  So, a typical use of the PyCIFRW module would look like
this:

>>> from PyCifRW import CifFile                    <- load the module
>>> df = CifFile.CifFile("ox2222.cif")             <- parse a CIF file
>>> df.keys()                                      <- list the block names
['6_Si_640b', '3_CePt4B', '5_CePd3B', '1_Si_640b', '2_CePt3B']
>>> ablock = df['6_Si_640b']                       <- select a block
>>> ablock['_diffrn_detector_type']                <- get a dataname value
'Fuji Photo Film Company,BaFBr:Eu phosphor'
>>> newblock = CifFile.CifBlock()                  <- create a new block
>>> newblock["_dummy_data_item"] = 'A single string'  <- set a data item
>>> newcif = CifFile.CifFile({"first_block":newblock}) <- create a new CIF
>>> newcif.keys()
['first_block']
>>> print newcif                                   <- get CIF so far

##########################################################################
#               Crystallographic Information Format file 
#               Produced by PyCifRW module
# 
#  This is a CIF file.  CIF has been adopted by the International
#  Union of Crystallography as the standard for data archiving and 
#  transmission.
#
#  For information on this file format, follow the CIF links at
#  http://www.iucr.org
##########################################################################

data_first_block
_dummy_data_item 'A single string'

>>>


-- 
_______________________________________________________________________
James Hester, ANBF                             KEK
e-mail: jrh@anbf2.kek.jp                       Oho 1-1
Phone: +81 298 64 7959                         Tsukuba, Ibaraki 305
  Fax: +81 298 64 7967                         Japan
________________________________________________________________________

Reply to: [list | sender only]
International Union of Crystallography

Scientific Union Member of the International Council for Science (admitted 1947). Member of CODATA, the ICSU Committee on Data. Member of ICSTI, the International Council for Scientific and Technical Information. Partner with UNESCO, the United Nations Educational, Scientific and Cultural Organization in the International Year of Crystallography 2014.

ICSU Scientific Freedom Policy

The IUCr observes the basic policy of non-discrimination and affirms the right and freedom of scientists to associate in international scientific activity without regard to such factors as ethnic origin, religion, citizenship, language, political stance, gender, sex or age, in accordance with the Statutes of the International Council for Science.