| 1 |
#! /usr/bin/perl -w |
| 2 |
# Before `make install' is performed this script should be runnable with |
| 3 |
# `make test'. After `make install' it should work as `perl test.pl' |
| 4 |
|
| 5 |
######################### We start with some black magic to print on failure. |
| 6 |
|
| 7 |
# Change 1..1 below to 1..last_test_to_print . |
| 8 |
# (It may become useful if the test is moved to ./t subdirectory.) |
| 9 |
|
| 10 |
BEGIN { $| = 1; print "1..10$/"; } |
| 11 |
END {print "not ok 1$/" unless $loaded;} |
| 12 |
use Xray::Xtal; |
| 13 |
$loaded = 1; |
| 14 |
print "ok 1$/"; |
| 15 |
|
| 16 |
######################### End of black magic. |
| 17 |
|
| 18 |
# Insert your test code below (better if it prints "ok 13" |
| 19 |
# (correspondingly "not ok 13") depending on the success of chunk 13 |
| 20 |
# of the test code): |
| 21 |
|
| 22 |
$epsilon = 0.00001; |
| 23 |
|
| 24 |
## instantiate a cell and set it dimensions |
| 25 |
$cell = Xray::Xtal::Cell -> new() -> make("A" => 6.342, "Alpha" => 47.8167); |
| 26 |
print "ok 2$/"; |
| 27 |
|
| 28 |
## start building cell for AgNO3 |
| 29 |
|
| 30 |
## title silver nitrate |
| 31 |
## space r 3 c |
| 32 |
## a = 6.342 |
| 33 |
## alpha= 47.8167 |
| 34 |
## rmax = 6.00 |
| 35 |
## core = Ag1 |
| 36 |
## atom |
| 37 |
## Ag 0.25000 0.25000 0.25000 Ag1 (2b) |
| 38 |
## N 0.00000 0.00000 0.00000 N1 (2a) |
| 39 |
## O 0.25000 -0.25000 0.00000 O1 (6e) |
| 40 |
|
| 41 |
## test Cell attributes |
| 42 |
($a, $alpha) = $cell -> attributes("A", "Alpha"); |
| 43 |
if ( (abs($a-6.342)<$epsilon) and (abs($alpha-47.8167)<$epsilon) ) { |
| 44 |
print "ok 3$/"; |
| 45 |
} else { |
| 46 |
print "not ok 3$/"; |
| 47 |
}; |
| 48 |
|
| 49 |
## now set the space group (this could have been done when |
| 50 |
## instantiated) |
| 51 |
$cell -> make("Space_group" => "r 3 c"); |
| 52 |
|
| 53 |
## does it know that this is the rhombohedral setting? |
| 54 |
($setting) = $cell -> attributes("Setting"); |
| 55 |
if ($setting eq "rhombohedral") { |
| 56 |
print "ok 4$/"; |
| 57 |
} else { |
| 58 |
print "not ok 4$/"; |
| 59 |
}; |
| 60 |
|
| 61 |
## did the other axes/angles get set? |
| 62 |
($b, $c, $beta, $gamma) = $cell -> attributes("B", "C", "Beta", "Gamma"); |
| 63 |
if ( (abs($b-6.342) < $epsilon) and |
| 64 |
(abs($c-6.342) < $epsilon) and |
| 65 |
(abs($beta-47.8167) < $epsilon) and |
| 66 |
(abs($gamma-47.8167) < $epsilon) ) { |
| 67 |
print "ok 5$/"; |
| 68 |
} else { |
| 69 |
print "not ok 5$/"; |
| 70 |
}; |
| 71 |
|
| 72 |
## cell volume |
| 73 |
## $pi = 3.14159265358979323844; |
| 74 |
## $ang_rad = $pi * 47.8167 / 180; |
| 75 |
## $vol = 6.342**3 * sqrt(1 - 3*cos($ang_rad)**2 + 2*cos($ang_rad)**3); |
| 76 |
$vol = 128.261102611632; |
| 77 |
($volume) = $cell -> attributes("Volume"); |
| 78 |
if (abs($vol-$volume) < $epsilon) { |
| 79 |
print "ok 6$/"; |
| 80 |
} else { |
| 81 |
print "not ok 6$/"; |
| 82 |
}; |
| 83 |
|
| 84 |
## metric tensor |
| 85 |
## $cosxx = ( cos($ang_rad)**2 - cos($ang_rad) ) / ( sin($ang_rad)**2 ); |
| 86 |
## $sinxx = sqrt(1-$cosxx**2); |
| 87 |
## $txx = $sinxx*sin($ang_rad); |
| 88 |
## $tyx = -( ($cosxx/($sinxx*sin($ang_rad)) ) + |
| 89 |
## (cos($ang_rad)*$cosxx)/($sinxx*sin($ang_rad))) |
| 90 |
## * ($sinxx*sin($ang_rad)); |
| 91 |
## $tyz = cos($ang_rad); |
| 92 |
## $tzx = -( $cosxx*$sinxx*sin($ang_rad) ) / $sinxx; |
| 93 |
## $tzz = sin($ang_rad); |
| 94 |
($txx, $tyx, $tyz, $tzx, $tzz) = |
| 95 |
(0.678575, 0.671505, 0.671505, 0.297687, 0.741000); |
| 96 |
($xx, $yx, $yz, $zx, $zz) = |
| 97 |
$cell -> attributes("Txx", "Tyx", "Tyz", "Tzx", "Tzz"); |
| 98 |
if ( (abs($txx-$xx) < $epsilon) and |
| 99 |
(abs($tyx-$yx) < $epsilon) and |
| 100 |
(abs($tyz-$yz) < $epsilon) and |
| 101 |
(abs($tzx-$zx) < $epsilon) and |
| 102 |
(abs($tzz-$zz) < $epsilon) ) { |
| 103 |
print "ok 7$/"; |
| 104 |
} else { |
| 105 |
print "not ok 7$/"; |
| 106 |
}; |
| 107 |
|
| 108 |
## ($bravais) = $cell -> attributes("Bravais"); |
| 109 |
## print join(", ", @{$bravais}), $/; |
| 110 |
|
| 111 |
## now lets start checking the site class |
| 112 |
|
| 113 |
@sites = (); |
| 114 |
$n = 0; |
| 115 |
|
| 116 |
## Ag 0.25000 0.25000 0.25000 Ag1 (2b) |
| 117 |
## N 0.00000 0.00000 0.00000 N1 (2a) |
| 118 |
## O 0.25000 -0.25000 0.00000 O1 (6e) |
| 119 |
|
| 120 |
## instantiate and set attributes of the three sites |
| 121 |
$sites[$n++] = Xray::Xtal::Site -> new() |
| 122 |
-> make(Element=>"Ag", X=>0.25, Y=>0.25, Z=>0.25); |
| 123 |
|
| 124 |
$sites[$n++] = Xray::Xtal::Site -> new() |
| 125 |
-> make(Element=>"N", X=>0, Y=>0, Z=>0 ); |
| 126 |
|
| 127 |
$sites[$n++] = Xray::Xtal::Site -> new() |
| 128 |
-> make(Element=>"O", X=>0.25, Y=>0.75, Z=>0 ); |
| 129 |
|
| 130 |
## and populate the cell with those sites. This line is key and |
| 131 |
## demonstrates the interplay between the two classes |
| 132 |
$cell -> populate(\@sites); |
| 133 |
|
| 134 |
## Ag 0.25000 0.25000 0.25000 Ag1 0 |
| 135 |
## Ag 0.75000 0.75000 0.75000 Ag1 1 |
| 136 |
## N 0.00000 0.00000 0.00000 N1 2 |
| 137 |
## N 0.50000 0.50000 0.50000 N1 3 |
| 138 |
## O 0.25000 0.75000 0.00000 O1 4 |
| 139 |
## O 0.00000 0.25000 0.75000 O1 5 |
| 140 |
## O 0.75000 0.00000 0.25000 O1 6 |
| 141 |
## O 0.25000 0.75000 0.50000 O1 7 |
| 142 |
## O 0.75000 0.50000 0.25000 O1 8 |
| 143 |
## O 0.50000 0.25000 0.75000 O1 9 |
| 144 |
|
| 145 |
@test = ("Ag 0.25000 0.25000 0.25000", |
| 146 |
"Ag 0.75000 0.75000 0.75000", |
| 147 |
"N 0.00000 0.00000 0.00000", |
| 148 |
"N 0.50000 0.50000 0.50000", |
| 149 |
"O 0.25000 0.75000 0.00000", |
| 150 |
"O 0.00000 0.25000 0.75000", |
| 151 |
"O 0.75000 0.00000 0.25000", |
| 152 |
"O 0.25000 0.75000 0.50000", |
| 153 |
"O 0.75000 0.50000 0.25000", |
| 154 |
"O 0.50000 0.25000 0.75000"); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
($contents) = $cell -> attributes("Contents"); |
| 159 |
|
| 160 |
## test number of items in the unit cell |
| 161 |
if ($#{$contents} == 9) { |
| 162 |
print "ok 8$/"; |
| 163 |
} else { |
| 164 |
print "not ok 8$/"; |
| 165 |
}; |
| 166 |
|
| 167 |
## make strings from the fractional positions in the unit cell and |
| 168 |
## compare them to stored strings |
| 169 |
$cell_test = 1; |
| 170 |
@list = @{$contents}; |
| 171 |
while (@list) { |
| 172 |
$this = shift(@list); |
| 173 |
|
| 174 |
($elem) = $ {$$this[3]} -> attributes("Element"); |
| 175 |
$this_site = sprintf "%-2s %7.5f %7.5f %7.5f", |
| 176 |
$elem, $$this[0], $$this[1], $$this[2]; |
| 177 |
|
| 178 |
$test = shift(@test); |
| 179 |
|
| 180 |
#print "$test $this_site $/"; |
| 181 |
$cell_test &&= ($test eq $this_site); |
| 182 |
}; |
| 183 |
|
| 184 |
if ($cell_test) { |
| 185 |
print "ok 9$/"; |
| 186 |
} else { |
| 187 |
print "not ok 9$/"; |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
## now test the conversion to cartesian coordinates |
| 192 |
|
| 193 |
@coords = (" 1.07588, 3.71484, 1.64684", |
| 194 |
" 3.22764, 11.14452, 4.94052", |
| 195 |
" 0.00000, 0.00000, 0.00000", |
| 196 |
" 2.15176, 7.42968, 3.29368", |
| 197 |
" 1.07588, 5.82117, 0.47198", |
| 198 |
" 0.00000, 4.77951, 3.52457", |
| 199 |
" 3.22764, 4.25868, 2.59080", |
| 200 |
" 1.07588, 7.95051, 2.82170", |
| 201 |
" 3.22764, 7.42968, 2.59080", |
| 202 |
" 2.15176, 6.90885, 4.46853",); |
| 203 |
|
| 204 |
$metric_test = 1; |
| 205 |
@list = @{$contents}; |
| 206 |
while (@list) { |
| 207 |
$this = shift(@list); |
| 208 |
($x, $y, $z) = $cell -> metric($$this[0], $$this[1], $$this[2]); |
| 209 |
$this_coord = sprintf "%8.5f, %8.5f, %8.5f", $x, $y, $z; |
| 210 |
$test = shift(@coords); |
| 211 |
#($test eq $this_coord) || ( print ">", $test, "< >", $this_coord, "<", $/); |
| 212 |
$metric_test &&= ($test eq $this_coord); |
| 213 |
}; |
| 214 |
|
| 215 |
if ($metric_test) { |
| 216 |
print "ok 10$/"; |
| 217 |
} else { |
| 218 |
print "not ok 10$/"; |
| 219 |
}; |
| 220 |
|
| 221 |
## Local Variables: |
| 222 |
## mode: cperl |
| 223 |
## End: |