File: ssg_symop_string

package info (click to toggle)
cod-tools 3.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 154,792 kB
  • sloc: perl: 57,588; sh: 36,842; ansic: 6,402; xml: 1,982; yacc: 1,117; makefile: 727; python: 166
file content (78 lines) | stat: -rwxr-xr-x 1,968 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
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2021-04-28 19:35:53 +0300 (Wed, 28 Apr 2021) $
#$Revision: 8738 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.7.0/scripts/ssg_symop_string $
#------------------------------------------------------------------------------
#*
#* Determine superspace group symmetry operators from symmetry matrices.
#* Superspace group symmetry operators are output as parsable strings
#* as described in the CIF _space_group_symop_ssg_operation_algebraic
#* data item.
#*
#* USAGE:
#*   $0 < input.matrix
#*   $0 input.matrix
#*   $0 input1.matrix input*.matrix
#**

use strict;
use warnings;
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage );
use COD::Spacegroups::Symop::SSGParse qw( string_from_symop );
use COD::ToolsVersion qw( get_version_string );

#* OPTIONS:
#*   --help, --usage
#*                     Output a short usage message (this message) and exit.
#*   --version
#*                     Output version information and exit.
#**
@ARGV = getOptions(
    '--help,--usage' => sub { usage; exit },
    '--version'      => sub { print get_version_string(), "\n"; exit }
);

my @matrix;

while(<>) {
    next if /^#/;
    next if /^\s*$/;
    chomp;
    if( /^\s*\[\s*$/ ) {
        @matrix = ();
        next;
    }
    if( /^\s*\[/ ) { # Matrix row
        s/^\s*\[\s*|\s*\]\s*$//g;
        my @row = split( /,\s*/ );
        push( @matrix, \@row );
        next;
    }
    if( /^\s*\]/ ) {
        print_commented_matrix( \@matrix );
        print string_from_symop( \@matrix ), "\n\n";
    }
}

sub print_commented_matrix
{
    my ($m) = @_;

    print "# [\n";
    for (@$m) {
        print "#   [ ";
        for (@$_) {
            printf "%2s, ", $_;
        }
        print " ]\n";
    }
    print "# ]\n";

    return;
}