| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from __future__ import print_function |
| 5 |
import sys |
| 6 |
from CifFile import CifFile, CifBlock |
| 7 |
cf = CifFile("loop_example.cif")["some_stuff"] |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
needed_items = [ |
| 13 |
"_atom_site_label", |
| 14 |
"_atom_site_type_symbol", |
| 15 |
"_atom_site_fract_x", |
| 16 |
"_atom_site_fract_y", |
| 17 |
"_atom_site_fract_z"] |
| 18 |
|
| 19 |
loopkeys = cf.GetLoopNames("_atom_site_label") |
| 20 |
if len(filter(lambda a,b=loopkeys:a not in b, needed_items)) != 0: |
| 21 |
print("Error: one or more items missing from atom_site_label loop") |
| 22 |
sys.exit() |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
nb = CifBlock() |
| 27 |
map(lambda a:nb.AddItem(a,cf[a]),needed_items) |
| 28 |
nb.CreateLoop(needed_items) |
| 29 |
df = CifFile() |
| 30 |
df.NewBlock("changed",nb) |
| 31 |
outfile = open("updated.cif",'w') |
| 32 |
outfile.write (df.WriteOut(comment="# This file has been updated")) |