File: cod_predeposition_check

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 (255 lines) | stat: -rwxr-xr-x 9,347 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2017-07-20 13:13:16 +0300 (Kt, 20 liep. 2017) $
#$Revision: 5477 $
#$URL: svn://www.crystallography.net/cod-tools/tags/v2.3/scripts/cod_predeposition_check $
#------------------------------------------------------------------------------
#*
#* Filter and check pairs of CIF and Fobs files for suitability for
#* deposition to COD database.
#*
#* USAGE:
#*    $0 --options input.cif input*.cif
#**

use strict;
use warnings;
use POSIX qw( strftime );
use COD::CIF::Data::CODPredepositionCheck qw( filter_and_check );
use COD::SOptions qw( getOptions get_value );
use COD::SUsage qw( usage options );
use COD::ToolsVersion;

my %database = (
        host  => 'www.crystallography.net',
        user  => 'cod_reader',
        name  => 'cod',
        table => 'data',
        password => '',
        platform => 'mysql',
    );

my @cif;
my @hkl;

my $deposition_type = 'published';
my $options;
$options->{'use_parser'} = 'c';

my $print_timestamps = 0;

my $tmp_dir;
my $tmp_file = "tmp-cod_predeposition_check-$$.tmp";

#* OPTIONS:
#*   -d, --database  cod
#*                     Use database "cod" to query for structures.
#*
#*   -h, --host   www.crystallography.net
#*   -s, --server www.crystallography.net
#*                     Query COD database on the host 'www.crystallography.net'.
#*
#*   -l, --localhost
#*                     Use database server on the localhost to query the COD
#*                     database.
#*
#*   -p, --port 3306
#*                     Use use the specified port (default 3306) to query
#*                     structures.
#*
#*   -t, --table  data
#*                     Use SQL table 'data' to query for structures.
#*
#*   -u, --user cod_reader
#*                     Use user name 'cod_reader' to access COD database;
#*                     this reader should be granted SELECT privilege, i.e.
#*                     should be able to read the COD database, without
#*                     supplying a password.
#*
#*   --password
#*                     Use the specified password (default empty) to connect.
#*
#*   --platform 'SQLite'
#*                     Use the SQL database platform 'SQLite' to query
#*                     structures (default 'mysql').
#*
#*   --cif input1.cif
#*                     Specify a CIF file to be deposited. Multiple CIF files
#*                     can be provided in a way like this:
#*                     $0 --cif input1.cif --cif input2.cif
#*
#*   --hkl, --fobs input1.hkl
#*                     Specify a Fobs file to be deposited. Multiple Fobs files
#*                     can be provided in way like this:
#*                     $0 --hkl input1.hkl --hkl input2.hkl
#*                     The order of the files is important in order to pair CIF
#*                     and Fobs files correctly.
#*
#*   --type, --deposition-type 'prepublication'
#*                     Specify the deposition type under which the structure
#*                     is to be deposited (default 'published').
#*
#*   --author-name 'Doe, J.'
#*                     Use the specified name as the name of the person
#*                     depositing the files.
#*
#*   --journal 'The Journal'
#*                     Use the specified journal name as if it was supplied
#*                     by the depositor during the 'prepublication' type
#*                     deposition.
#*
#*   --hold-period 3
#*                     Use the specified hold period as if it was supplied by
#*                     the depositor.
#*
#*   --replace
#*                     Treat given files as replacements for previously
#*                     deposited data.
#*   --no-replace, --dont-replace
#*                     Do not treat given files as replacements for previously
#*                     deposited data (default).
#*
#*   --release
#*                     Treat given files as if they were previously deposited
#*                     as prepublication material and should now be released
#*                     into the public domain.
#*   --no-release, --dont-release
#*                     Do not treat given files as if they were previously
#*                     deposited as prepublication material and should now
#*                     be released into the public domain (default).
#*
#*   --bypass-checks
#*                     Do not check CIF files for compliance with COD
#*                     requirements.
#*   --dont-bypass-checks, --no-bypass-checks
#*                     Check CIF files for compliance with COD requirements
#*                     (default).
#*
#*   --split-pdcif
#*                     Output powder diffraction data blocks as a HKL file.
#*   --dont-split-pdcif, --no-split-pdcif
#*                     Output powder diffraction data blocks as part of the
#*                     CIF file (default).
#*
#*   --print-timestamps
#*                     Print timestamps to STDOUT at the start and end of
#*                     each CIF file deposition.
#*   --no-print-timestamps, --dont-print-timestamps
#*                     Do not print timestamps to STDOUT at the start and end
#*                     of each CIF file deposition (default)
#*
#*   --tmp-dir, --temp-dir
#*                     Use the specified temporary directory (default './').
#*
#*   --use-perl-parser
#*                     Use Perl parser to parse CIF files.
#*   --use-c-parser
#*                     Use C parser to parse CIF files (default).
#*
#*   --help, --usage
#*                     Output a short usage message (this message) and exit.
#*   --version
#*                     Output version information and exit.
#**
@ARGV = getOptions(
    '-d,--database'  => \$database{name},
    '-l,--localhost' => sub { $database{host} = 'localhost' },
    '-h,--host'      => \$database{host},
    '-p,--port'      => \$database{port},
    '-s,--server'    => \$database{host},
    '-t,--table'     => \$database{table},
    '-u,--user'      => \$database{user},
    '--password'     => \$database{password},
    '--platform'     => \$database{platform},

    '--cif' => sub { push @cif, get_value() },
    '--hkl,--fobs' => sub { @hkl[(@cif-1 > 0) ? @cif-1 : 0] = get_value() },

    '--type,--deposition-type' => \$deposition_type,

    '--bypass-checks'      => sub { $options->{bypass_checks} = 1 },
    '--dont-bypass-checks' => sub { delete( $options->{bypass_checks} ) },
    '--no-bypass-checks'   => sub { delete( $options->{bypass_checks} ) },

    '--replace'      => sub { $options->{replace} = 1 },
    '--dont-replace' => sub { delete( $options->{replace} ) },
    '--no-replace'   => sub { delete( $options->{replace} ) },

    '--release'      => sub { $options->{release} = 1 },
    '--dont-release' => sub { delete( $options->{release} ) },
    '--no-release'   => sub { delete( $options->{release} ) },

    '--hold-period' => \$options->{hold_period},
    '--journal'     => \$options->{journal},
    '--author-name' => \$options->{author_name},

    '--split-pdcif'      => sub { $options->{split_pdcif} = 1 },
    '--dont-split-pdcif' => sub { delete( $options->{split_pdcif} ) },
    '--no-split-pdcif'   => sub { delete( $options->{split_pdcif} ) },

    '--print-timestamps'      => sub { $print_timestamps = 1 },
    '--dont-print-timestamps' => sub { $print_timestamps = 0 },
    '--no-print-timestamps'   => sub { $print_timestamps = 0 },

    '--tmp-dir,--temp-dir' => \$tmp_dir,

    '--use-perl-parser' => sub { $options->{use_parser} = 'perl' },
    '--use-c-parser'    => sub { $options->{use_parser} = 'c' },
    '--options'         => sub { options; exit },
    '--help,--usage'    => sub { usage; exit },
    '--version'         => sub { print 'cod-tools version ',
                                 $COD::ToolsVersion::Version, "\n";
                                 exit }
);

push @cif, @ARGV;

@cif = ('-') unless @cif;

binmode STDOUT, ':encoding(UTF-8)';
binmode STDERR, ':encoding(UTF-8)';

if( $tmp_dir ) {
    $tmp_file = $tmp_dir . '/' . $tmp_file;
}

if( exists $options->{release} ) {
    $options->{replace} = 1;
}
if( $options->{release} && $deposition_type eq 'prepublication' ) {
    die "$0:: ERROR, structure can be released either as published or " .
        'personal communication.' . "\n";
}

for my $i (0..@cif-1) {
    print "START $cif[$i] " . strftime( "%Y-%m-%d %T\n", localtime )
        if $print_timestamps;
    my( $cif, $hkl );
    eval {
        ( $cif, $hkl ) =
            filter_and_check( $cif[$i],
                              $cif[$i],
                              $hkl[$i],
                              $hkl[$i],
                              \%database,
                              $deposition_type,
                              $tmp_file,
                              $options );
    };
    if( $@ ) {
        if ( $@ =~ /[^.]\n$/ ) {
            $@ =~ s/\n$/.\n/
        };
        print {*STDERR} $@;
    } else {
        if ( defined $cif ) { print map { "CIF $_\n" } split m/\n/, $cif };
        if ( defined $hkl ) { print map { "HKL $_\n" } split m/\n/, $hkl };
    }
    print "FINISH $cif[$i] " . strftime( "%Y-%m-%d %T\n", localtime )
        if $print_timestamps;
    unlink $tmp_file if -e $tmp_file;
}