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
|
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
if 0;
#------------------------------------------------------------------------------
#$Author: andrius $
#$Date: 2023-12-15 10:13:24 +0200 (Fri, 15 Dec 2023) $
#$Revision: 9850 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.11.0/scripts/cif_set_value $
#------------------------------------------------------------------------------
#*
#* Set specified CIF data items to the given values.
#*
#* USAGE:
#* $0 --options input1.cif input*.cif
#**
use strict;
use warnings;
use COD::CIF::Tags::Manage qw( contains_data_item set_tag );
use COD::CIF::Parser qw( parse_cif );
use COD::CIF::Tags::CanonicalNames qw( canonicalize_all_names );
use COD::CIF::Tags::Print qw( print_cif );
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage options );
use COD::ErrorHandler qw( process_parser_messages );
use COD::ToolsVersion qw( get_version_string );
my $die_on_error_level = {
ERROR => 1,
WARNING => 0,
NOTE => 0
};
my $use_parser = 'c';
my $tag = '_atom_site_occupancy';
my $value = 1.0;
my $add_if_nonexistent = 0;
#* OPTIONS:
#* -t, --tag _atom_site_occupancy
#* Specify which data item to set.
#* -v, --value 1.0
#* Specify a new value for that data item.
#*
#* --add-tag
#* If the given data item does not exist in a data
#* block, add it with the specified value.
#* --no-add-tag
#* Only overwrite already existing data items, do not
#* add new ones (default).
#*
#* --use-perl-parser
#* --use-c-parser
#* Specify parser to parse CIF files (default: C parser).
#*
#* --help, --usage
#* Output a short usage message (this message) and exit.
#* --version
#* Output version information and exit.
#**
@ARGV = getOptions(
'-t,--tag' => \$tag,
'-v,--value' => \$value,
'--use-perl-parser' => sub { $use_parser = 'perl' },
'--use-c-parser' => sub { $use_parser = 'c' },
'--add-tag' => sub { $add_if_nonexistent = 1 },
'--no-add-tag' => sub { $add_if_nonexistent = 0 },
'--options' => sub { options; exit },
'--help,--usage' => sub { usage; exit },
'--version' => sub { print get_version_string(), "\n"; exit }
);
@ARGV = ("-") unless @ARGV;
binmode STDOUT, ':encoding(UTF-8)';
binmode STDERR, ':encoding(UTF-8)';
for my $filename (@ARGV) {
my $options = { 'parser' => $use_parser, 'no_print' => 1 };
my ( $data, $err_count, $messages ) = parse_cif( $filename, $options );
process_parser_messages( $messages, $die_on_error_level );
next if ( $err_count > 0 );
canonicalize_all_names( $data );
for my $dataset (@$data) {
if( contains_data_item( $dataset, $tag ) ) {
for my $cif_value (@{$dataset->{values}{$tag}}) {
$cif_value = $value;
}
} elsif( $add_if_nonexistent ) {
set_tag( $dataset, $tag, $value );
}
}
for my $dataset( @$data ) {
print_cif( $dataset, {
exclude_misspelled_tags => 0,
preserve_loop_order => 1,
fold_long_fields => 0,
keep_tag_order => 1,
});
}
}
|