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
|
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2022-09-25 19:15:11 +0300 (Sun, 25 Sep 2022) $
#$Revision: 9431 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.11.0/scripts/cif_symop_apply $
#------------------------------------------------------------------------------
#*
#* Apply symmetry operator(s) to all atoms in a CIF.
#*
#* USAGE:
#* $0 --options input1.cif input*.cif
#**
use strict;
use warnings;
use COD::CIF::Parser qw( parse_cif );
use COD::Spacegroups::Symop::Parse qw( symop_from_string );
use COD::Spacegroups::Symop::Algebra qw( symop_mul symop_vector_mul );
use COD::CIF::Tags::Print qw( print_cif );
use COD::SOptions qw( getOptions get_value );
use COD::SUsage qw( usage options );
use COD::ErrorHandler qw( process_parser_messages report_message );
use COD::ToolsVersion qw( get_version_string );
my $die_on_error_level = {
ERROR => 1,
WARNING => 0,
NOTE => 0
};
my $use_parser = 'c';
my @symops = ();
#* OPTIONS:
#* -s, --symop, --symmetry-operator -x,-y,z
#* Apply the specified symmetry operator.
#*
#* -a, --add-symop, --add-symmetry-operator -x,-y,z
#* Add the specified symmetry operator to the applied
#* operator list.
#*
#* --use-perl-parser
#* Use development CIF parser written in Perl.
#* --use-c-parser
#* Use faster C/Yacc CIF parser. Default.
#*
#* --help, --usage
#* Output a short usage message (this message) and exit.
#* --version
#* Output version information and exit.
#**
@ARGV = getOptions(
'-s,--symop,--symmetry-operator' => sub { @symops = (get_value()) },
'-a,--add-symop,--add-symmetry-operator' => \@symops,
'--use-perl-parser' => sub { $use_parser = 'perl' },
'--use-c-parser' => sub { $use_parser = 'c' },
'--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)';
my $symop_matrix = symop_from_string('x,y,z');
for my $symop (@symops) {
$symop_matrix = symop_mul
( $symop_matrix, symop_from_string( $symop ));
}
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 );
if( !@{$data} || !defined $data->[0] || !defined $data->[0]{'name'} ) {
report_message( {
'program' => $0,
'filename' => $filename,
'err_level' => 'WARNING',
'message' => 'file seems to be empty'
}, $die_on_error_level->{'WARNING'} );
next;
}
for my $datablock (@{$data}) {
my $values = $datablock->{values};
for( my $i = 0; $i <= $#{$values->{'_atom_site_fract_x'}}; $i ++ ) {
my @xyz;
for my $data_name ( '_atom_site_fract_x',
'_atom_site_fract_y',
'_atom_site_fract_z' ) {
my $coord = $values->{$data_name}[$i];
$coord =~ s/[(][0-9]+[)]$//;
push @xyz, $coord;
};
my $new_xyz = symop_vector_mul( $symop_matrix, \@xyz );
$values->{'_atom_site_fract_x'}[$i] = $new_xyz->[0];
$values->{'_atom_site_fract_y'}[$i] = $new_xyz->[1];
$values->{'_atom_site_fract_z'}[$i] = $new_xyz->[2];
}
do {
local $, = ' ';
local $\ = "\n";
print @{$datablock->{'tags'}};
} if 0;
print_cif( $datablock, {
'dictionary_tags' => $datablock->{'values'},
'dictionary_tag_list' => $datablock->{'tags'},
});
}
}
|