File: cif_printout_Python

package info (click to toggle)
cod-tools 2.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 114,852 kB
  • sloc: perl: 53,336; sh: 23,842; ansic: 6,318; xml: 1,982; yacc: 1,112; makefile: 716; python: 158; sql: 73
file content (90 lines) | stat: -rwxr-xr-x 3,538 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
# -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
#$Author: andrius $
#$Revision: 5703 $
#$URL: svn://www.crystallography.net/cod-tools/tags/v2.3/scripts/cif_printout_Python $
#$Date: 2017-11-02 17:43:23 +0200 (Kt, 02 lapkr. 2017) $
#$Id: cif_printout_Python 5703 2017-11-02 15:43:23Z andrius $
#------------------------------------------------------------------------------
#*
#* Parse CIF file and print out the structure generated by CIF parser.
#**

import argparse
import pprint
import sys
from pycodcif import parse, CifParserException

def version():
    import os
    from os.path import realpath,dirname
    from subprocess import call
    directory = os.path.dirname(os.path.realpath(__file__))
    call( "{}/cod-tools-version".format(directory) )
    sys.exit()

parser = argparse.ArgumentParser(description='Parse CIF file and print out '
                                             'the structure generated by '
                                             'the CIF parser')

parser.add_argument("--do-not-unprefix-text",
                    dest='do_not_unprefix_text',
                    action='store_const', const=1)
parser.add_argument("--do-not-unfold-text",
                    dest='do_not_unfold_text',
                    action='store_const', const=1)
parser.add_argument("--fix-errors",
                    dest='fix_errors',
                    action='store_const', const=1)
parser.add_argument("--fix-duplicate-tags-with-same-values",
                    dest='fix_duplicate_tags_with_same_values',
                    action='store_const', const=1)
parser.add_argument("--fix-duplicate-tags-with-empty-values",
                    dest='fix_duplicate_tags_with_empty_values',
                    action='store_const', const=1)
parser.add_argument("--fix-data-header",
                    dest='fix_data_header',
                    action='store_const', const=1)
parser.add_argument("--fix-datablock-names",
                    dest='fix_datablock_names',
                    action='store_const', const=1)
parser.add_argument("--fix-string-quotes",
                    dest='fix_string_quotes',
                    action='store_const', const=1)
parser.add_argument("--fix-missing-closing-double-quote",
                    dest='fix_missing_closing_double_quote',
                    action='store_const', const=1)
parser.add_argument("--fix-missing-closing-single-quote",
                    dest='fix_missing_closing_single_quote',
                    action='store_const', const=1)
parser.add_argument("--fix-ctrl-z",
                    dest='fix_ctrl_z',
                    action='store_const', const=1)
parser.add_argument("--allow-uqstring-brackets",
                    dest='allow_uqstring_brackets',
                    action='store_const', const=1)
parser.add_argument("--version", dest='version',
                    action='store_const', const=1)
parser.add_argument("files", nargs='*')

options = vars(parser.parse_args(args=sys.argv[1:]))
for key in options.keys():
    if not options[key]:
        options.pop(key)

files = options.pop('files',[])
if not files:
    files = ['-']

if 'version' in options.keys():
    version()

for filename in files:
    try:
        data, errcount, _ = parse(filename, options)
        pprint.PrettyPrinter().pprint(data)
        print len(data[0]['tags'][0])
        sys.stderr.write("{} error(s) detected\n".format(errcount))
    except CifParserException:
        sys.exit(1)