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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
#! /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/cif_mpod_v3_to_v1 $
#------------------------------------------------------------------------------
#*
#* Convert MPOD structures from MPOD dictionary V1 to MPOD dict. V3 based
#* data names.
#*
#* USAGE:
#* $0 --options input1.cif input*.cif
#**
use strict;
use warnings;
use COD::CIF::Parser qw( parse_cif );
use COD::CIF::Tags::Manage qw( exclude_tag );
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 report_message );
use COD::ToolsVersion qw( get_version_string );
my $die_on_error_level = {
ERROR => 1,
WARNING => 0,
NOTE => 0
};
my $use_parser = "c";
#* OPTIONS:
#* --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(
"--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 }
);
my @scalar_property_tags = qw(
_prop_residual_resistivity_ratio
_prop_residual_resistivity_ratio_high_temperature
_prop_residual_resistivity_ratio_low_temperature
_prop_superconducting_critical_temperature_thermodynamic
_prop_superconducting_critical_temperature_onset
_prop_superconducting_critical_temperature_onset_90
_prop_superconducting_critical_temperature_mid_50
_prop_superconducting_critical_temperature_offset_10
_prop_superconducting_zero_resistivity_temperature
_prop_superconducting_resistivity_transition_width
_prop_magnetic_paramagnetic_critical_temperature_Neel
_prop_magnetic_paramagnetic_critical_temperature_Neel_transitionwidth
_prop_magnetic_antiferromagnetic_ordering_temperature_Neel
);
my @property_tags = qw(
_prop_heat_capacity_C
_prop_dielectric_permittivity_relative_epsrij
_prop_dielectric_permittivity_relative_epsrijS
_prop_dielectric_permittivity_relative_epsrijT
_prop_dielectric_stiffness_relative_betrijS
_prop_dielectric_stiffness_relative_betrijT
_prop_elastic_stiffness_cij
_prop_elastic_stiffness_cijD
_prop_elastic_stiffness_cijE
_prop_elastic_compliance_sij
_prop_elastic_compliance_sijD
_prop_elastic_compliance_sijE
_prop_electric_resistivity_rhoeij
_prop_electric_remnant_polarisation_Pri
_prop_electric_coercive_field_Eci
_prop_internal_friction_Qij-1
_prop_electromechanical_coupling_kij
_prop_optical_index_ordinary_no
_prop_optical_index_extraordinary_ne
_prop_piezoelectric_gij
_prop_piezoelectric_eij
_prop_piezoelectric_hij
_prop_piezoelectric_dij
_prop_piezooptic_piij
_prop_superconducting_critical_field1_Hc1i
_prop_superconducting_critical_field2_Hc2i
_prop_superconducting_irreversibility_field_Hirri
_prop_superconducting_coherence_length_ksii
_prop_superconducting_penetration_depth_lambdai
_prop_electrostriction_Dij
_prop_electrostriction_Dprimeij
_prop_photoelastic_pij
_prop_thermal_conductivity_kappaij
_prop_thermal_diffusivity_kappadij
_prop_thermal_expansion_alphaij
_prop_thermal_expansion_Tij
_prop_thermoelectric_Seebeck_Seij
);
my @condition_tags = qw(
_prop_conditions_temperature
_prop_conditions_temperature_range_begin
_prop_conditions_temperature_range_end
_prop_conditions_temperature_cycle
_prop_conditions_pressure
_prop_conditions_frequency
_prop_conditions_magnetic_field
_prop_conditions_wavelength
);
my @measurement_tags = qw(
_prop_measurement_method
_prop_measurement_poling
_prop_frame
);
my @data_tags = qw(
_prop_data_label
_prop_data_value
_prop_data_tensorial_index
);
my @categories = qw(
prop_dielectric
prop_elastic
prop_electric
prop_electromechanical_coupling
prop_electrostriction
prop_frame
prop_heat_capacity
prop_internal_friction
prop_magnetic
prop_measurement
prop_optical
prop_photoelastic
prop_piezoelectric
prop_piezooptic
prop_residual_resistivity
prop_superconducting
prop_symmetry
prop_thermal
prop_thermoelectric
);
@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 );
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};
my $tags = $datablock->{tags};
my @conditions = ();
for my $condition (@condition_tags) {
my $condition_key = lc( $condition );
if( exists $values->{$condition_key} ) {
push( @conditions, $condition );
}
}
my %condition_values = ();
if( exists $values->{_prop_conditions_label} ) {
for my $i (0..$#{$values->{_prop_conditions_label}}) {
my $key = $values->{_prop_conditions_label}[$i];
my $condition_text = "";
my $separator = "";
for my $condition (@conditions) {
$condition_text .= $separator .
$values->{$condition}[$i];
$separator = " ";
}
$condition_values{$key} = $condition_text;
}
}
my @property_data = ();
my %property_names = ();
my %property_labels = ();
for my $property (@property_tags) {
my $property_key = lc( $property );
if( exists $values->{$property_key} ) {
$property_names{$property} = 1;
$property =~ /_([^_]*?)$/;
my $property_label = $1;
$property_labels{$property} = $property_label;
for my $i (0..$#{$values->{$property_key}}) {
next if $values->{$property_key}[$i] eq ".";
my $property_category = get_category( $property );
my $property_condition_link =
"_${property_category}_condition_label";
my $tensorial_index_key =
"_${property_category}_tensorial_index";
my $method_key =
"_${property_category}_measurement_method";
my $tensorial_index =
$values->{$tensorial_index_key}[$i];
my $measurement_method =
$values->{$method_key}[$i];
my @property_data_row =
( $property_label, $tensorial_index,
$values->{$property_key}[$i], $measurement_method );
if( @conditions ) {
if( exists $values->{$property_condition_link} ) {
my $condition_key =
$values->{$property_condition_link}[$i];
if( defined $condition_values{$condition_key} ) {
push( @property_data_row,
$condition_values{$condition_key} );
} else {
push( @property_data_row, "?" );
}
} else {
push( @property_data_row, "." );
}
}
push( @property_data, \@property_data_row );
}
}
}
## use COD::Serialise qw( serialiseRef );
## serialiseRef( \@conditions );
## serialiseRef( \%condition_values );
## serialiseRef( \@property_data );
# Delete previous value tags:
my @link_tags =
map { ("_${_}_conditions_label",
"_${_}_tensorial_index",
"_${_}_condition_label",
"_${_}_measurement_method") } @categories;
push( @link_tags, "_prop_conditions_label" );
for my $tag (@condition_tags, @property_tags, @data_tags, @link_tags) {
exclude_tag( $datablock, lc($tag) );
}
exclude_tag( $datablock, "_prop_measurement_method" );
# Print out the rest of the CIF data:
print_cif( $datablock, {
exclude_misspelled_tags => 0,
preserve_loop_order => 1,
fold_long_fields => 1,
folding_width => 78,
dictionary_tags => { map {$_,$_} @{$datablock->{tags}} },
dictionary_tag_list => $datablock->{tags},
keep_tag_order => 1,
});
# Print out the collected tensor values if there are any:
for my $property (sort keys %property_names ) {
print $property, " '$property_labels{$property}'\n";
}
if( @property_data ) {
print "loop_\n";
print "_prop_data_label\n";
print "_prop_data_tensorial_index\n";
print "_prop_data_value\n";
print "_prop_measurement_method\n";
for my $key (@conditions) {
print $key, "\n";
}
for my $property_value_row (@property_data) {
print join( " ", @$property_value_row ), "\n"
}
}
}
}
sub get_category
{
my ( $property ) = @_;
for my $category (@categories) {
if( $property =~ /^_${category}_/ ) {
return $category
}
}
return;
}
|