File: symops

package info (click to toggle)
cod-tools 3.1.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 149,700 kB
  • sloc: perl: 56,946; sh: 32,158; ansic: 6,385; xml: 1,982; yacc: 1,117; makefile: 728; python: 166
file content (110 lines) | stat: -rwxr-xr-x 3,652 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
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2019-12-05 21:37:22 +0200 (Thu, 05 Dec 2019) $ 
#$Revision: 7549 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.1.0/scripts/symops $
#------------------------------------------------------------------------------
#*
#* Print out symmetry operators for a given space group, or print out
#* those symmetry operators that belong to the group, while diagnosing
#* as errors those operators that do not belong to the group.
#*
#* USAGE:
#*   $0 --options P212121
#*   $0 --options P212121 -- -y,-x,z -x,y,z
#**

use strict;
use warnings;
use COD::CIF::Data;
use COD::Spacegroups::Symop::Parse qw( 
    symop_string_canonical_form
);
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage );
use COD::ToolsVersion;

my $quiet = 0; # Be quiet, do not print symmtry operators that are
               # found to belong to the group.

my $do_not_report_errors = 0; # Do not output error messages when the
                              # argument symmetry operator does not
                              # belong to the group.

#* OPTIONS:
#*   -q, --quiet
#*                     Do not output recognised operator names (default).
#*   -v, --verbose
#*                     Print out symmetry operators, negate the '-q' option.
#*
#*   --error-messages
#*                     Print error messages about unrecognised symmetry
#*                     operators (default).
#*   --no-error-messages 
#*                     Do not print error messages about missing
#*                     symmetry operators, just return a non-zero
#*                     status if such are encountered.
#*
#*   --help, --usage
#*                     Output a short usage message (this message) and exit.
#*
#*   --version
#*                     Output version information and exit.
#**
@ARGV = getOptions(
    "-q,--quiet"   => sub { $quiet = 1 },
    "-v,--verbose" => sub { $quiet = 0 },

    "--no-error-messages" => sub { $do_not_report_errors = 1 },
    "--error-messages"   => sub { $do_not_report_errors = 0 },
    
    "--help,--usage" => sub { usage; exit },
    '--version'      => sub { print 'cod-tools version ',
                              $COD::ToolsVersion::Version, "\n";
                              exit }
);

if( @ARGV < 1 ) {
    print STDERR "$0: usage: $0 SGNAME\n";
    print STDERR " e.g.: $0 P212121\n";
    exit 1;
}

my $spacegroup_name = shift( @ARGV );

my $sym_data =
    COD::CIF::Data::lookup_space_group( 'hermann_mauguin', $spacegroup_name );

if( defined $sym_data ) {
    local $\ = "\n";
    if( @ARGV == 0 ) {
        for my $symop (@{$sym_data->{symops}}) {
            print symop_string_canonical_form( $symop );
        }
    } else {
        my $status = 0;
        my %symops = map {
            symop_string_canonical_form( $_ ) => 1
        } @{$sym_data->{symops}};
        for my $symop (@ARGV) {
            my $symop_key = symop_string_canonical_form( $symop );
            if( exists $symops{$symop_key} ) {
                print $symop_key, "\t", $symop
                    unless $quiet;
            } else {
                print STDERR "$0: symetry operator '$symop' ('$symop_key') " .
                    "was not found in spacegroup '$spacegroup_name'"
                    unless $do_not_report_errors;
                $status = 3;
            }
        }
        exit $status;
    }
} else {
    print STDERR "$0: spacegroup '$spacegroup_name' could not be identified\n";
    exit 2;
}