aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-10-01 17:26:12 +0200
committerThomas White <taw@physics.org>2019-03-11 16:49:36 +0100
commit5ce8e318bcd3389acb28685c930e23087bf8722b (patch)
tree19dd6c418537c6b7e6144ec88252f1799584d3fb /src
parent08abdc901b1268aea325c04f4a5697c90a6a7d45 (diff)
cell_tool: Add --compare (doesn't seem to work yet for some reason)
Diffstat (limited to 'src')
-rw-r--r--src/cell_tool.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/cell_tool.c b/src/cell_tool.c
index 70d80552..3450c299 100644
--- a/src/cell_tool.c
+++ b/src/cell_tool.c
@@ -68,6 +68,82 @@ static void show_help(const char *s)
}
+static int comparecells(UnitCell *cell, const char *comparecell,
+ double ltl, double atl)
+{
+ signed int i[9];
+ const int maxorder = 2;
+ UnitCell *cell2;
+
+ STATUS("Comparing with: %s\n", comparecell);
+
+ cell2 = load_cell_from_file(comparecell);
+ if ( cell2 == NULL ) {
+ ERROR("Failed to load unit cell from '%s'\n", comparecell);
+ return 1;
+ }
+ if ( validate_cell(cell2) ) {
+ ERROR("Comparison cell is invalid.\n");
+ return 1;
+ }
+ STATUS("------------------> The reference unit cell:\n");
+ cell_print(cell2);
+
+ STATUS("Comparing cells up to %ix each lattice length.\n", maxorder);
+ STATUS("Reciprocal axis length tolerance %f %%\n", ltl*100.0);
+ STATUS("Reciprocal angle tolerance %f degrees\n", rad2deg(atl));
+ STATUS("This will take about 30 seconds. Please wait...\n");
+
+ for ( i[0]=-maxorder; i[0]<=+maxorder; i[0]++ ) {
+ for ( i[1]=-maxorder; i[1]<=+maxorder; i[1]++ ) {
+ for ( i[2]=-maxorder; i[2]<=+maxorder; i[2]++ ) {
+ for ( i[3]=-maxorder; i[3]<=+maxorder; i[3]++ ) {
+ for ( i[4]=-maxorder; i[4]<=+maxorder; i[4]++ ) {
+ for ( i[5]=-maxorder; i[5]<=+maxorder; i[5]++ ) {
+ for ( i[6]=-maxorder; i[6]<=+maxorder; i[6]++ ) {
+ for ( i[7]=-maxorder; i[7]<=+maxorder; i[7]++ ) {
+ for ( i[8]=-maxorder; i[8]<=+maxorder; i[8]++ ) {
+
+ UnitCellTransformation *tfn;
+ UnitCell *nc;
+ IntegerMatrix *m;
+ int j, k;
+ int l = 0;
+
+ m = intmat_new(3, 3);
+ for ( j=0; j<3; j++ ) {
+ for ( k=0; k<3; k++ ) {
+ intmat_set(m, j, k, i[l++]);
+ }
+ }
+
+ if ( intmat_det(m) < 1 ) continue;
+
+ tfn = tfn_from_intmat(m);
+ nc = cell_transform(cell, tfn);
+
+ if ( cells_are_similar(cell2, nc, ltl, atl) ) {
+ STATUS("-----------------------------------------------"
+ "-------------------------------------------\n");
+ cell_print(nc);
+ intmat_print(m);
+ }
+
+ intmat_free(m);
+ tfn_free(tfn);
+ cell_free(nc);
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
}
@@ -436,6 +512,7 @@ int main(int argc, char *argv[])
if ( mode == CT_FINDAMBI ) return find_ambi(cell, sym, ltl, atl);
if ( mode == CT_UNCENTER ) return uncenter(cell, out_file);
if ( mode == CT_RINGS ) return all_rings(cell, sym);
+ if ( mode == CT_COMPARE ) return comparecells(cell, comparecell, ltl, atl);
/* FIXME: Everything else */
ERROR("Sorry, this mode of operation is not yet implemented.\n");