From ed1fd7f414b11c5db3848bd8c2a216af7df928f8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 27 Sep 2018 14:19:03 +0200 Subject: cell_tool --uncenter: Write unit cell to file --- src/cell_tool.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cell_tool.c b/src/cell_tool.c index 48cbeaa7..3e638179 100644 --- a/src/cell_tool.c +++ b/src/cell_tool.c @@ -53,6 +53,7 @@ static void show_help(const char *s) "\n" " -h, --help Display this help message.\n" " -p, --pdb= Get unit cell from (PDB or CrystFEL format).\n" +" -o Output unit cell file.\n" "\n" " Actions:\n" " --find-ambi Find indexing ambiguities for the cell.\n" @@ -183,7 +184,7 @@ static int find_ambi(UnitCell *cell, SymOpList *sym, float *tols) } -static int uncenter(UnitCell *cell) +static int uncenter(UnitCell *cell, const char *out_file) { UnitCell *cnew; UnitCellTransformation *trans; @@ -196,6 +197,16 @@ static int uncenter(UnitCell *cell) STATUS("------------------> The decentering transformation:\n"); tfn_print(trans); + if ( out_file != NULL ) { + FILE *fh = fopen(out_file, "w"); + if ( fh == NULL ) { + ERROR("Failed to open '%s'\n", out_file); + return 1; + } + write_cell(cnew, fh); + fclose(fh); + } + return 0; } @@ -221,12 +232,14 @@ int main(int argc, char *argv[]) SymOpList *sym = NULL; int mode = CT_NOTHING; char *comparecell = NULL; + char *out_file = NULL; /* Long options */ const struct option longopts[] = { {"help", 0, NULL, 'h'}, {"pdb", 1, NULL, 'p'}, {"tolerance", 1, NULL, 2}, + {"output", 1, NULL, 'o'}, /* Modes of operation */ {"find-ambi", 0, &mode, CT_FINDAMBI}, @@ -240,7 +253,7 @@ int main(int argc, char *argv[]) }; /* Short options */ - while ((c = getopt_long(argc, argv, "hp:y:", + while ((c = getopt_long(argc, argv, "hp:y:o:", longopts, NULL)) != -1) { switch (c) { @@ -253,6 +266,10 @@ int main(int argc, char *argv[]) cell_file = strdup(optarg); break; + case 'o' : + out_file = strdup(optarg); + break; + case 'y' : sym_str = strdup(optarg); break; @@ -318,7 +335,7 @@ int main(int argc, char *argv[]) } if ( mode == CT_FINDAMBI ) return find_ambi(cell, sym, tols); - if ( mode == CT_UNCENTER ) return uncenter(cell); + if ( mode == CT_UNCENTER ) return uncenter(cell, out_file); /* FIXME: Everything else */ ERROR("Sorry, this mode of operation is not yet implemented.\n"); -- cgit v1.2.3