From 8aaf6a5ab8a41f4b852380af7f0c73b43424a1d1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 7 Aug 2024 22:54:10 +0200 Subject: [PATCH] Specify phase shift location using cmd option (#53) Previously, it was specified through the `CLEED_PHASE` system variable. --- cleedpy/cleed/include/leed_func.h | 6 +- cleedpy/cleed/src/leed.c | 6 +- cleedpy/cleed/src/linpphase.c | 344 --------------- cleedpy/cleed/src/linpphasend.c | 440 +++++++------------ cleedpy/cleed/src/linprdbulnd.c | 17 +- cleedpy/cleed/src/linprdovlnd.c | 16 +- cleedpy/cli/leed.py | 5 +- cleedpy/interface/cleed.py | 6 +- examples/cleed_example_old/run.sh | 4 - examples/cleedpy_example_intermediate/run.sh | 2 - examples/ni111_2x2O/run_cleedpy.sh | 2 - 11 files changed, 179 insertions(+), 669 deletions(-) delete mode 100644 cleedpy/cleed/src/linpphase.c delete mode 100755 examples/cleed_example_old/run.sh diff --git a/cleedpy/cleed/include/leed_func.h b/cleedpy/cleed/include/leed_func.h index a29088e..097a933 100644 --- a/cleedpy/cleed/include/leed_func.h +++ b/cleedpy/cleed/include/leed_func.h @@ -25,18 +25,16 @@ int inpovlay_sym(struct cryst_str *, struct atom_str *); mat inp_mat_lm(mat , int , const char *); /* read phase shifts; file linpphase.c */ -int inp_phase ( char * , real * , struct phs_str **); int inp_phase_nd( char * , real * , int , struct phs_str **); int upd_phase( int ); /* read bulk parameters; file linprdbul.c */ -int inp_rdbul (struct cryst_str ** , struct phs_str ** , char *); -int inp_rdbul_nd(struct cryst_str ** , struct phs_str ** , char *); +int inp_rdbul_nd(struct cryst_str ** , struct phs_str ** , char *, char *); int inp_rdbulsym(struct cryst_str ** , struct phs_str ** , char *); /* read overlayer parameters; file linprdovl.c */ int inp_rdovl (struct cryst_str ** , struct phs_str ** , struct cryst_str * , char *); -int inp_rdovl_nd(struct cryst_str **, struct phs_str **, struct cryst_str *, char *); +int inp_rdovl_nd(struct cryst_str **, struct phs_str **, struct cryst_str *, char *, char *); int inp_rdovlsym(struct cryst_str ** , struct phs_str ** , struct cryst_str * , char *); /* read other parameters; file linprdpar.c */ int inp_rdpar(struct var_str **, struct eng_str **, struct cryst_str * , char *); diff --git a/cleedpy/cleed/src/leed.c b/cleedpy/cleed/src/leed.c index 961ca95..ba610ad 100644 --- a/cleedpy/cleed/src/leed.c +++ b/cleedpy/cleed/src/leed.c @@ -34,7 +34,7 @@ void print_phase_shift(struct phs_str phs_shift) } -CleedResult leed(char * par_file, char * bul_file) +CleedResult leed(char * par_file, char * bul_file, char *phase_path) { struct cryst_str *bulk=NULL; struct cryst_str *over=NULL; @@ -66,9 +66,9 @@ CleedResult leed(char * par_file, char * bul_file) struct eng_str *eng=NULL; // Read input parameters - inp_rdbul_nd(&bulk, &phs_shifts, bul_file); + inp_rdbul_nd(&bulk, &phs_shifts, bul_file, phase_path); inp_rdpar(&v_par, &eng, bulk, bul_file); - inp_rdovl_nd(&over, &phs_shifts, bulk, par_file); + inp_rdovl_nd(&over, &phs_shifts, bulk, par_file, phase_path); inp_showbop(bulk, over, phs_shifts); for (i=0; (phs_shifts + i)->lmax != I_END_OF_LIST; i++) print_phase_shift(phs_shifts[i]); diff --git a/cleedpy/cleed/src/linpphase.c b/cleedpy/cleed/src/linpphase.c deleted file mode 100644 index 62a4f1b..0000000 --- a/cleedpy/cleed/src/linpphase.c +++ /dev/null @@ -1,344 +0,0 @@ -/********************************************************************** - GH/02.09.97 - WB/26.02.98 - file contains function: - - upd_phase - Update the number of phase shifts. - inp_phase - Read phase shifts from an input file and store them. - -Changes: - - GH/04.07.94 - Creation - GH/19.01.95 - add eng_max and eng_min - GH/08.08.95 - update i_phase - GH/02.09.97 - Set input path by environment variable CLEED_PHASE - (makes PHASE_PATH obsolete) - WB/26.02.98 - Correct control output - -*********************************************************************/ - -#include -#if defined (__MACH__) - #include -#else - #include -#endif -#include -#include -#include -#include - -#include "leed.h" -#include "leed_def.h" - -/* -#define CONTROL -*/ -#define WARNING -#define ERROR - -#ifndef GEO_TOLERANCE /* should be defined in "leed_def.h" */ -#define GEO_TOLERANCE 0.0001 /* ca. 0.00005 A */ -#endif - -static int i_phase = 0; /* number of atom types */ - -/********************************************************************/ - -int upd_phase( int n) - -/********************************************************************* - Update the number of phase shifts i_phase - -INPUT: - int n number i_phase will be set to. - -RETURN VALUE: - i_phase (i.e. equal to the argument) - -*********************************************************************/ -{ - i_phase = n; - return(i_phase); -} /* end of function upd_phase */ - -/********************************************************************/ - -int inp_phase( char * phaseinp, real * dr, struct phs_str **p_phs_shifts ) - -/********************************************************************* - - Read phase shifts from an input file and store them. - - INPUT: - - char * phaseinp (input) Either full path name of phase shift file - if starting with "/" or tag for type of atom (will be expanded - into a full filename by using CLEED_PHASE and extension ".phs"). - - real * dr (input) displacement vector for thermic vibrations - - struct phs_str **p_phs_shifts (output) phase shifts. - - DESIGN: - - The phase shifts in the input file must be for increasing energies. - The storage scheme is: - - - -*********************************************************************/ -{ -FILE *inp_stream; - -char filename[STRSZ]; -char linebuffer[STRSZ]; -char eng_type[STRSZ]; - -struct phs_str *phs_shifts; - -int i; -int i_str, i_eng; - -int neng, lmax, nl; /* neng = No. of energies to be read - lmax = max. quantum number; - nl = No. of phase shifts = lmax + 1 - */ - -real eng_scale; - -real faux; - -/*********************************************************************** - Create name of input file: - - If phaseinp is a full path (starting with '/'), this is used as - name of the input file. - - Otherwise the filename is put together from CLEED_PHASE, phaseinp - and the extension '.phs'. - - Check whether environment variable CLEED_PHASE exists at all. -***********************************************************************/ - - if( *phaseinp != '/') - { - if(getenv("CLEED_PHASE") == NULL) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase) environment variable CLEED_PHASE not defined\n"); -#endif - exit(1); - } - sprintf(filename, "%s/%s.phs",getenv("CLEED_PHASE"),phaseinp); - } - else - sprintf(filename, "%s",phaseinp); - - if(i_phase > 0) - { -/* - Compare filename and dr with previous phaseshifts. Return the - corresponding phase shift number if the same combination has already - been read. -*/ - for(i=0; i< i_phase; i++) - if( (!strcmp( (*p_phs_shifts + i)->input_file, filename) ) && - ( R_fabs(dr[1] - (*p_phs_shifts + i)->dr[1]) < GEO_TOLERANCE ) && - ( R_fabs(dr[2] - (*p_phs_shifts + i)->dr[2]) < GEO_TOLERANCE ) && - ( R_fabs(dr[3] - (*p_phs_shifts + i)->dr[3]) < GEO_TOLERANCE ) ) - { - return(i); - break; - } - i_phase ++; - *p_phs_shifts = (struct phs_str *)realloc( - *p_phs_shifts, (i_phase + 1) * sizeof(struct phs_str) ); - } - else - { - i_phase ++; - *p_phs_shifts = (struct phs_str *) malloc( 2 * sizeof(struct phs_str) ); - } - -/* Terminate list of phase shifts */ - - (*(p_phs_shifts) + i_phase)->lmax = I_END_OF_LIST; - - - phs_shifts = *(p_phs_shifts) + i_phase-1; - -/* write dr to phs_shifts */ - for(i=0; i<=3; i++) phs_shifts->dr[i] = dr[i]; - -/******************************************************************** - Open and Read input file for a new set of phase shifts -********************************************************************/ - -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Reading file \"%s\", i_phase = %d\n", - filename, i_phase-1); -#endif - -/* - Open input file. - Copy the full filename into phs_shifts->input_file. -*/ - - if( (inp_stream = fopen(filename, "r")) == NULL) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): could not open file \"%s\"\n",filename); -#endif - exit(1); - } - - phs_shifts->input_file = strdup(filename); - -/******************************************************************** - Read the first line of the input file which contains the number of - energies to be read in (neng) and the maximum phase shift quantum - number (lmax). -********************************************************************/ - -/* read comment lines */ - while( *fgets(linebuffer, STRSZ, inp_stream) == '#'); - - if ( linebuffer == NULL) /* EOF found */ - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): unexpected EOF found while reading file \"%s\"\n", - filename); -#endif - exit(1); - } - else if( sscanf(linebuffer, "%d %d %s", &neng, &lmax, eng_type) < 2) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): improper input line in file \"%s\":\n%s", - filename, linebuffer); -#endif - exit(1); - } - -/* - Define energy scale according to eng_type. The default is - input in Hartree units (27.18 eV) -*/ - if( !strncmp(eng_type,"eV",2) || !strncmp(eng_type,"EV",2) ) - { - eng_scale = 1./HART; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in eV\n"); -#endif - } - else if( !strncmp(eng_type,"Ry",2) || !strncmp(eng_type,"RY",2) ) - { - eng_scale = 2./HART; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in Rydberg (13.59 eV)\n"); -#endif - } - else - { - eng_scale = 1.; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in Hartree (27.18 eV)\n"); -#endif - } - - -/******************************************************************** - Read energies and phase shifts. - Find max and min energy - NB: The search for blank or '-' after reading each number is needed - because of the FORTRAN format used for the VHT input files which does - not have any blank character between negative numbers. -********************************************************************/ - - phs_shifts->lmax = lmax; - nl = lmax + 1; - - phs_shifts->energy = (real *)malloc( neng * sizeof(real) ); - phs_shifts->pshift = (real *)malloc( neng * nl * sizeof(real) ); - - - for( i_eng = 0; - (i_eng < neng) && (fgets(linebuffer, STRSZ, inp_stream) != NULL); - i_eng ++) - { -#ifdef REAL_IS_DOUBLE - sscanf(linebuffer, "%le", phs_shifts->energy+i_eng); -#endif -#ifdef REAL_IS_FLOAT - sscanf(linebuffer, "%e", phs_shifts->energy+i_eng); -#endif - phs_shifts->energy[i_eng] *= eng_scale; - - if (i_eng == 0) - phs_shifts->eng_min = phs_shifts->energy[i_eng]; - else - phs_shifts->eng_max = phs_shifts->energy[i_eng]; - - if( fgets(linebuffer, STRSZ, inp_stream) != NULL) - { - for( i_str = 0, i = 0; ipshift+i_eng*nl+i); -#endif -#ifdef REAL_IS_FLOAT - sscanf(linebuffer + i_str, "%e", phs_shifts->pshift+i_eng*nl+i); -#endif - while((linebuffer[i_str] == ' ') || (linebuffer[i_str] == '-')) i_str ++; - while((linebuffer[i_str] != ' ') && (linebuffer[i_str] != '-')) i_str ++; - } - } - else - { - phs_shifts->energy[i_eng] = 0.; - phs_shifts->eng_max = phs_shifts->energy[i_eng-1]; - break; - } - } - - phs_shifts->neng = i_eng; - -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Number of energies = %d, lmax = %d\n", - phs_shifts->neng, phs_shifts->lmax); - fprintf(STDCTR,"\n\t E(H)"); - for(i=0; ineng; i_eng ++) - { - fprintf(STDCTR,"\t%7.4f", phs_shifts->energy[i_eng]); - for(i=0; ipshift[i_eng*nl+i] != 0.0) - fprintf(STDCTR,"\t%7.4f", phs_shifts->pshift[i_eng*nl+i]); - else - fprintf(STDCTR,"\t -- "); - } - fprintf(STDCTR,"\n"); - } - fprintf(STDCTR,"\n"); -#endif - -#ifdef WARNING - if(phs_shifts->neng != neng) - { - fprintf(STDWAR, - " *** warning (inp_phase): EOF found before reading all phase shifts:\n"); - fprintf(STDWAR, - " expected energies: %3d, found: %3d, file: %s\n", - neng, i_eng+1, filename); - } -#endif - - return(i_phase - 1); -} /* end of function inp_phase */ diff --git a/cleedpy/cleed/src/linpphasend.c b/cleedpy/cleed/src/linpphasend.c index 1ee884c..e57a385 100644 --- a/cleedpy/cleed/src/linpphasend.c +++ b/cleedpy/cleed/src/linpphasend.c @@ -28,20 +28,9 @@ #include #include #include - #include "leed.h" #include "leed_def.h" -/* -#define CONTROL -*/ -#define WARNING -#define ERROR - -#ifndef GEO_TOLERANCE /* should be defined in "leed_def.h" */ -#define GEO_TOLERANCE 0.0001 /* ca. 0.00005 A */ -#endif - static int i_phase = 0; /* number of atom types */ /********************************************************************/ @@ -59,289 +48,176 @@ RETURN VALUE: *********************************************************************/ { - i_phase = n; - return(i_phase); + i_phase = n; + return(i_phase); } /* end of function upd_phase */ /********************************************************************/ -int inp_phase_nd( char * phaseinp, real * dr, int t_type, - struct phs_str **p_phs_shifts ) - +int inp_phase_nd( char * filename, real * dr, int t_type, struct phs_str **p_phs_shifts) /********************************************************************* - Read phase shifts from an input file and store them. - - INPUT: - - char * phaseinp (input) Either full path name of phase shift file - if starting with "/" or tag for type of atom (will be expanded - into a full filename by using CLEED_PHASE and extension ".phs"). - - real * dr (input) displacement vector for thermic vibrations + Read phase shifts from an input file and store them. - struct phs_str **p_phs_shifts (output) phase shifts. + INPUT: - DESIGN: + char * filename (input) path to the phase shift file + real * dr (input) displacement vector for thermic vibrations - The phase shifts in the input file must be for increasing energies. - The storage scheme is: + struct phs_str **p_phs_shifts (output) phase shifts. + DESIGN: + The phase shifts in the input file must be for increasing energies. + The storage scheme is: *********************************************************************/ { -FILE *inp_stream; - -char filename[STRSZ]; -char linebuffer[STRSZ]; -char eng_type[STRSZ]; - -struct phs_str *phs_shifts; - -int i; -int i_str, i_eng; - -int neng, lmax, nl; /* neng = No. of energies to be read - lmax = max. quantum number; - nl = No. of phase shifts = lmax + 1 - */ - -real eng_scale; - -real faux; - -/*********************************************************************** - Create name of input file: - - If phaseinp is a full path (starting with '/'), this is used as - name of the input file. - - Otherwise the filename is put together from CLEED_PHASE, phaseinp - and the extension '.phs'. - - Check whether environment variable CLEED_PHASE exists at all. -***********************************************************************/ - - if( *phaseinp != '/') - { - if(getenv("CLEED_PHASE") == NULL) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase) environment variable CLEED_PHASE not defined\n"); -#endif - exit(1); - } - sprintf(filename, "%s/%s.phs",getenv("CLEED_PHASE"),phaseinp); - } - else - sprintf(filename, "%s",phaseinp); - - if(i_phase > 0) - { -/* - Compare filename, dr, and t_type with previous phaseshifts. Return the - corresponding phase shift number if the same combination has already - been read. -*/ - for(i=0; i< i_phase; i++) - if( (!strcmp( (*p_phs_shifts + i)->input_file, filename) ) && - ( R_fabs(dr[1] - (*p_phs_shifts + i)->dr[1]) < GEO_TOLERANCE ) && - ( R_fabs(dr[2] - (*p_phs_shifts + i)->dr[2]) < GEO_TOLERANCE ) && - ( R_fabs(dr[3] - (*p_phs_shifts + i)->dr[3]) < GEO_TOLERANCE ) && - ( t_type == (*p_phs_shifts + i)->t_type ) - ) - { - return(i); - break; - } - i_phase ++; - *p_phs_shifts = (struct phs_str *)realloc( - *p_phs_shifts, (i_phase + 1) * sizeof(struct phs_str) ); - } - else - { - i_phase ++; - *p_phs_shifts = (struct phs_str *) malloc( 2 * sizeof(struct phs_str) ); - } - -/* Terminate list of phase shifts */ - - (*(p_phs_shifts) + i_phase)->lmax = I_END_OF_LIST; - - - phs_shifts = *(p_phs_shifts) + i_phase-1; - -/* write dr and t_type to phs_shifts */ - for(i=0; i<=3; i++) phs_shifts->dr[i] = dr[i]; - phs_shifts->t_type = t_type; - -/******************************************************************** - Open and Read input file for a new set of phase shifts -********************************************************************/ - -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Reading file \"%s\", i_phase = %d\n", - filename, i_phase-1); -#endif - -/* - Open input file. - Copy the full filename into phs_shifts->input_file. -*/ - - if( (inp_stream = fopen(filename, "r")) == NULL) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): could not open file \"%s\"\n",filename); -#endif - exit(1); - } - - phs_shifts->input_file = strdup(filename); - -/******************************************************************** - Read the first line of the input file which contains the number of - energies to be read in (neng) and the maximum phase shift quantum - number (lmax). -********************************************************************/ - -/* read comment lines */ - while( *fgets(linebuffer, STRSZ, inp_stream) == '#'); - - if ( linebuffer == NULL) /* EOF found */ - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): unexpected EOF found while reading file \"%s\"\n", - filename); -#endif - exit(1); - } - else if( sscanf(linebuffer, "%d %d %s", &neng, &lmax, eng_type) < 2) - { -#ifdef ERROR - fprintf(STDERR, - " *** error (inp_phase): improper input line in file \"%s\":\n%s", - filename, linebuffer); -#endif - exit(1); - } - -/* - Define energy scale according to eng_type. The default is - input in Hartree units (27.18 eV) -*/ - if( !strncmp(eng_type,"eV",2) || !strncmp(eng_type,"EV",2) ) - { - eng_scale = 1./HART; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in eV\n"); -#endif - } - else if( !strncmp(eng_type,"Ry",2) || !strncmp(eng_type,"RY",2) ) - { - eng_scale = 2.; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in Rydberg (13.59 eV)\n"); -#endif - } - else - { - eng_scale = 1.; -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Energy input in Hartree (27.18 eV)\n"); -#endif - } - - -/******************************************************************** - Read energies and phase shifts. - Find max and min energy - NB: The search for blank or '-' after reading each number is needed - because of the FORTRAN format used for the VHT input files which does - not have any blank character between negative numbers. -********************************************************************/ - - phs_shifts->lmax = lmax; - nl = lmax + 1; - - phs_shifts->energy = (real *)calloc( neng, sizeof(real) ); - phs_shifts->pshift = (real *)calloc( neng * nl, sizeof(real) ); - - - for( i_eng = 0; - (i_eng < neng) && (fgets(linebuffer, STRSZ, inp_stream) != NULL); - i_eng ++) - { -#ifdef REAL_IS_DOUBLE - sscanf(linebuffer, "%le", phs_shifts->energy+i_eng); -#endif -#ifdef REAL_IS_FLOAT - sscanf(linebuffer, "%e", phs_shifts->energy+i_eng); -#endif - phs_shifts->energy[i_eng] *= eng_scale; - - if (i_eng == 0) - phs_shifts->eng_min = phs_shifts->energy[i_eng]; - else - phs_shifts->eng_max = phs_shifts->energy[i_eng]; - - if( fgets(linebuffer, STRSZ, inp_stream) != NULL) - { - for( i_str = 0, i = 0; ipshift+i_eng*nl+i); -#endif -#ifdef REAL_IS_FLOAT - sscanf(linebuffer + i_str, "%e", phs_shifts->pshift+i_eng*nl+i); -#endif - while((linebuffer[i_str] == ' ') || (linebuffer[i_str] == '-')) i_str ++; - while((linebuffer[i_str] != ' ') && (linebuffer[i_str] != '-')) i_str ++; - } - } - else - { - phs_shifts->energy[i_eng] = 0.; - phs_shifts->eng_max = phs_shifts->energy[i_eng-1]; - break; - } - } - - phs_shifts->neng = i_eng; - -#ifdef CONTROL - fprintf(STDCTR,"(inp_phase): Number of energies = %d, lmax = %d\n", - phs_shifts->neng, phs_shifts->lmax); - fprintf(STDCTR,"\n\t E(H)"); - for(i=0; ineng; i_eng ++) - { - fprintf(STDCTR,"\t%7.4f", phs_shifts->energy[i_eng]); - for(i=0; ipshift[i_eng*nl+i] != 0.0) - fprintf(STDCTR,"\t%7.4f", phs_shifts->pshift[i_eng*nl+i]); - else - fprintf(STDCTR,"\t -- "); - } - fprintf(STDCTR,"\n"); - } - fprintf(STDCTR,"\n"); -#endif - -#ifdef WARNING - if(phs_shifts->neng != neng) - { - fprintf(STDWAR, - " *** warning (inp_phase): EOF found before reading all phase shifts:\n"); - fprintf(STDWAR, - " expected energies: %3d, found: %3d, file: %s\n", - neng, i_eng+1, filename); - } -#endif - - return(i_phase - 1); + FILE *inp_stream; + char linebuffer[STRSZ]; + char eng_type[STRSZ]; + + struct phs_str *phs_shifts; + + int i, i_str, i_eng; + int neng, lmax, nl; /* neng = No. of energies to be read + lmax = max. quantum number; + nl = No. of phase shifts = lmax + 1 + */ + + real eng_scale; + real faux; + + if(i_phase > 0) + { + /* Compare filename, dr, and t_type with previous phaseshifts. Return the + corresponding phase shift number if the same combination has already been read. */ + for(i=0; i< i_phase; i++) + if( (!strcmp( (*p_phs_shifts + i)->input_file, filename) ) && + ( R_fabs(dr[1] - (*p_phs_shifts + i)->dr[1]) < GEO_TOLERANCE ) && + ( R_fabs(dr[2] - (*p_phs_shifts + i)->dr[2]) < GEO_TOLERANCE ) && + ( R_fabs(dr[3] - (*p_phs_shifts + i)->dr[3]) < GEO_TOLERANCE ) && + ( t_type == (*p_phs_shifts + i)->t_type ) + ) + { + return(i); + break; + } + i_phase ++; + *p_phs_shifts = (struct phs_str *)realloc(*p_phs_shifts, (i_phase + 1) * sizeof(struct phs_str) ); + } + else + { + i_phase ++; + *p_phs_shifts = (struct phs_str *) malloc( 2 * sizeof(struct phs_str) ); + } + + // Terminate list of phase shifts. + + (*(p_phs_shifts) + i_phase)->lmax = I_END_OF_LIST; + + + phs_shifts = *(p_phs_shifts) + i_phase-1; + + // Write dr and t_type to phs_shifts. + for(i=0; i<=3; i++) phs_shifts->dr[i] = dr[i]; + phs_shifts->t_type = t_type; + + /******************************************************************** + Open and Read input file for a new set of phase shifts + ********************************************************************/ + + // Open input file. Copy the full filename into phs_shifts->input_file. + if( (inp_stream = fopen(filename, "r")) == NULL) + { + fprintf(STDERR, " *** error (inp_phase): could not open file \"%s\"\n",filename); + exit(1); + } + + phs_shifts->input_file = strdup(filename); + + /******************************************************************** + Read the first line of the input file which contains the number of + energies to be read in (neng) and the maximum phase shift quantum + number (lmax). + ********************************************************************/ + + // Read comment lines + while( *fgets(linebuffer, STRSZ, inp_stream) == '#'); + + if ( linebuffer == NULL) /* EOF found */ + { + fprintf(STDERR, " *** error (inp_phase): unexpected EOF found while reading file \"%s\"\n", filename); + exit(1); + } + else if( sscanf(linebuffer, "%d %d %s", &neng, &lmax, eng_type) < 2) + { + fprintf(STDERR, " *** error (inp_phase): improper input line in file \"%s\":\n%s", filename, linebuffer); + exit(1); + } + + // Define energy scale according to eng_type. The default is input in Hartree units (27.18 eV). + if( !strncmp(eng_type,"eV",2) || !strncmp(eng_type,"EV",2) ) + { + eng_scale = 1./HART; + } + else if( !strncmp(eng_type,"Ry",2) || !strncmp(eng_type,"RY",2) ) + { + eng_scale = 2.; + } + else + { + eng_scale = 1.; + } + + + /******************************************************************** + Read energies and phase shifts. + Find max and min energy + NB: The search for blank or '-' after reading each number is needed + because of the FORTRAN format used for the VHT input files which does + not have any blank character between negative numbers. + ********************************************************************/ + + phs_shifts->lmax = lmax; + nl = lmax + 1; + + phs_shifts->energy = (real *)calloc( neng, sizeof(real) ); + phs_shifts->pshift = (real *)calloc( neng * nl, sizeof(real) ); + + + for( i_eng = 0; (i_eng < neng) && (fgets(linebuffer, STRSZ, inp_stream) != NULL); i_eng ++) + { + sscanf(linebuffer, "%le", phs_shifts->energy+i_eng); + phs_shifts->energy[i_eng] *= eng_scale; + if (i_eng == 0) + phs_shifts->eng_min = phs_shifts->energy[i_eng]; + else + phs_shifts->eng_max = phs_shifts->energy[i_eng]; + + if( fgets(linebuffer, STRSZ, inp_stream) != NULL) + { + for( i_str = 0, i = 0; ipshift+i_eng*nl+i); + while((linebuffer[i_str] == ' ') || (linebuffer[i_str] == '-')) i_str ++; + while((linebuffer[i_str] != ' ') && (linebuffer[i_str] != '-')) i_str ++; + } + } + else + { + phs_shifts->energy[i_eng] = 0.; + phs_shifts->eng_max = phs_shifts->energy[i_eng-1]; + break; + } + } + phs_shifts->neng = i_eng; + + if(phs_shifts->neng != neng) + { + fprintf(STDWAR, " *** warning (inp_phase): EOF found before reading all phase shifts:\n"); + fprintf(STDWAR, " expected energies: %3d, found: %3d, file: %s\n", neng, i_eng+1, filename); + } + + return(i_phase - 1); } /* end of function inp_phase */ diff --git a/cleedpy/cleed/src/linprdbulnd.c b/cleedpy/cleed/src/linprdbulnd.c index 8dc4738..df8d6ad 100644 --- a/cleedpy/cleed/src/linprdbulnd.c +++ b/cleedpy/cleed/src/linprdbulnd.c @@ -52,9 +52,8 @@ GH/29.09.00 - calculate dr2 for dmt input in function inp_debtemp /********************************************************************/ -int inp_rdbul_nd (struct cryst_str **p_bulk_par, - struct phs_str **p_phs_shifts, - char *filename) +int inp_rdbul_nd (struct cryst_str **p_bulk_par, struct phs_str **p_phs_shifts, char *filename, char *phase_path) + /********************************************************************* Read all the bulk parameters that do not change during a search @@ -91,6 +90,7 @@ FILE *inp_stream; char linebuffer[STRSZ]; char phaseinp[STRSZ]; char whatnext[STRSZ]; +char filename_path[STRSZ]; int i,j, iaux; /* counter, dummy variables */ int i_c, i_str; @@ -389,17 +389,13 @@ struct atom_str * atoms_rd; /* this vector of structure atom_str is atoms_rd = ( struct atom_str *) realloc( atoms_rd, (i_atoms+2) * sizeof(struct atom_str) ); -#ifdef REAL_IS_DOUBLE iaux = sscanf(linebuffer+i_str+3 ," %s %lf %lf %lf %s %lf %lf %lf", -#endif -#ifdef REAL_IS_FLOAT - iaux = sscanf(linebuffer+i_str+3 ," %s %f %f %f %s %f %f %f", -#endif phaseinp, atoms_rd[i_atoms].pos+1, atoms_rd[i_atoms].pos+2, atoms_rd[i_atoms].pos+3, whatnext, vaux+1, vaux+2, vaux+3); + sprintf(filename_path, "%s/%s.phs", phase_path, phaseinp); for(i=1; i<=3; i++) atoms_rd[i_atoms].pos[i] /= BOHR; @@ -504,11 +500,8 @@ struct atom_str * atoms_rd; /* this vector of structure atom_str is } /* input of atomic phase shifts */ - atoms_rd[i_atoms].type = inp_phase_nd(phaseinp, vaux, - atoms_rd[i_atoms].t_type, - p_phs_shifts); + atoms_rd[i_atoms].type = inp_phase_nd(filename_path, vaux, atoms_rd[i_atoms].t_type, p_phs_shifts); bulk_par->ntypes = MAX(atoms_rd[i_atoms].type+1, bulk_par->ntypes); - i_atoms ++; break; } /* case 'p' */ diff --git a/cleedpy/cleed/src/linprdovlnd.c b/cleedpy/cleed/src/linprdovlnd.c index 6b82d9c..c7d95dd 100644 --- a/cleedpy/cleed/src/linprdovlnd.c +++ b/cleedpy/cleed/src/linprdovlnd.c @@ -49,10 +49,7 @@ GH/29.09.00 - calculate dr2 for dmt input in function inp_debtemp /********************************************************************/ -int inp_rdovl_nd (struct cryst_str **p_over_par, - struct phs_str **p_phs_shifts, - struct cryst_str *bulk_par, - char *filename) +int inp_rdovl_nd (struct cryst_str **p_over_par, struct phs_str **p_phs_shifts, struct cryst_str *bulk_par, char *filename, char *phase_path) /********************************************************************* Read all the overlayer parameters that do change during a search @@ -86,6 +83,7 @@ FILE *inp_stream; char linebuffer[STRSZ]; char phaseinp[STRSZ]; char whatnext[STRSZ]; +char filename_path[STRSZ]; int i,j, iaux; /* counter, dummy variables */ int i_c, i_str; @@ -203,17 +201,13 @@ struct atom_str *atoms_rd; /* this vector of structure atom_str is atoms_rd = ( struct atom_str *) realloc( atoms_rd, (i_atoms+2) * sizeof(struct atom_str) ); -#ifdef REAL_IS_DOUBLE iaux = sscanf(linebuffer+i_str+3 ," %s %lf %lf %lf %s %lf %lf %lf", -#endif -#ifdef REAL_IS_FLOAT - iaux = sscanf(linebuffer+i_str+3 ," %s %f %f %f %s %f %f %f", -#endif phaseinp, atoms_rd[i_atoms].pos+1, atoms_rd[i_atoms].pos+2, atoms_rd[i_atoms].pos+3, whatnext, vaux+1, vaux+2, vaux+3); + sprintf(filename_path, "%s/%s.phs", phase_path, phaseinp); for(i=1; i<=3; i++) atoms_rd[i_atoms].pos[i] /= BOHR; @@ -310,9 +304,7 @@ struct atom_str *atoms_rd; /* this vector of structure atom_str is } /* input of atomic phase shifts */ - atoms_rd[i_atoms].type = inp_phase_nd(phaseinp, vaux, - atoms_rd[i_atoms].t_type, - p_phs_shifts); + atoms_rd[i_atoms].type = inp_phase_nd(filename_path, vaux, atoms_rd[i_atoms].t_type, p_phs_shifts); over_par->ntypes = MAX(atoms_rd[i_atoms].type+1, over_par->ntypes); i_atoms ++; diff --git a/cleedpy/cli/leed.py b/cleedpy/cli/leed.py index 8f99a0e..39cb88d 100644 --- a/cleedpy/cli/leed.py +++ b/cleedpy/cli/leed.py @@ -69,12 +69,15 @@ def leed( "leed.inp", "--input", "-i", help="Input file with parameters" ), bulk_file: str = typer.Option(None, "--bulk", "-b", help="Bulk file"), # noqa: B008 + phase_path: str = typer.Option( # noqa: B008 + "PHASE", "--phase", "-p", help="Phase path" + ), output_file: str = typer.Option( # noqa: B008 "leed.out", "--output", "-o", help="Output file" ), # noqa: B008 ): """Leed CLI.""" - result = call_cleed(parameters_file, bulk_file) + result = call_cleed(parameters_file, bulk_file, phase_path) print_cleed_results(result, output_file) diff --git a/cleedpy/interface/cleed.py b/cleedpy/interface/cleed.py index 5336c7a..d422afd 100644 --- a/cleedpy/interface/cleed.py +++ b/cleedpy/interface/cleed.py @@ -234,13 +234,13 @@ def get_cleed_lib() -> CDLL: return cdll.LoadLibrary(cleed_lib) -def call_cleed(parameters_file, bulk_file): +def call_cleed(parameters_file, bulk_file, phase_path): lib = get_cleed_lib() - lib.leed.argtypes = [c_char_p, c_char_p] + lib.leed.argtypes = [c_char_p, c_char_p, c_char_p] lib.leed.restype = CleedResult - result = lib.leed(parameters_file.encode(), bulk_file.encode()) + result = lib.leed(parameters_file.encode(), bulk_file.encode(), phase_path.encode()) return result diff --git a/examples/cleed_example_old/run.sh b/examples/cleed_example_old/run.sh deleted file mode 100755 index 5d7c51b..0000000 --- a/examples/cleed_example_old/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -export CLEED_PHASE=./PHASE -EXECUTABLE=../../cleedpy/cleed/bin/test_cleed - -${EXECUTABLE} diff --git a/examples/cleedpy_example_intermediate/run.sh b/examples/cleedpy_example_intermediate/run.sh index 3ca2620..e4f5f8a 100755 --- a/examples/cleedpy_example_intermediate/run.sh +++ b/examples/cleedpy_example_intermediate/run.sh @@ -1,3 +1 @@ -export CLEED_PHASE=./PHASE - cleedpy-leed -i leed.inp -b leed.inp -o leed.res diff --git a/examples/ni111_2x2O/run_cleedpy.sh b/examples/ni111_2x2O/run_cleedpy.sh index 9a9ec7b..1282179 100755 --- a/examples/ni111_2x2O/run_cleedpy.sh +++ b/examples/ni111_2x2O/run_cleedpy.sh @@ -1,3 +1 @@ -export CLEED_PHASE=./PHASE - cleedpy-leed -i Ni111_2x2O.inp -b Ni111_2x2O.inp -o cleedpy.res