From 78dac2f42140d319f8bf02efff318e27def95e04 Mon Sep 17 00:00:00 2001 From: "Kurt A. O'Hearn" <ohearnku@msu.edu> Date: Mon, 10 May 2021 16:12:12 -0400 Subject: [PATCH] sPuReMD: fix bug for BGF files if no CRYSTX line supplied (simulation box dimensions). --- sPuReMD/src/geo_tools.c | 56 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/sPuReMD/src/geo_tools.c b/sPuReMD/src/geo_tools.c index 03037f48..3b361e20 100644 --- a/sPuReMD/src/geo_tools.c +++ b/sPuReMD/src/geo_tools.c @@ -689,6 +689,40 @@ void Read_BGF( const char * const bgf_file, reax_system* system, control_params atom_cnt = 0; token_cnt = 0; + while ( fgets( line, MAX_LINE, bgf ) ) + { + /* read new line and tokenize it */ + strncpy( backup, line, MAX_LINE - 1 ); + backup[MAX_LINE - 1] = '\0'; + token_cnt = Tokenize( line, &tokens, MAX_TOKEN_LEN ); + + if ( strncmp( tokens[0], "CRYSTX", 6 ) == 0 ) + { + sscanf( backup, BGF_CRYSTX_FORMAT, descriptor, + s_a, s_b, s_c, s_alpha, s_beta, s_gamma ); + + /* compute full volume tensor from the angles */ + Setup_Box( sstrtod( s_a, __FILE__, __LINE__ ), + sstrtod( s_b, __FILE__, __LINE__ ), + sstrtod( s_c, __FILE__, __LINE__ ), + sstrtod( s_alpha, __FILE__, __LINE__ ), + sstrtod( s_beta, __FILE__, __LINE__ ), + sstrtod( s_gamma, __FILE__, __LINE__ ), + &system->box ); + + crystx_found = TRUE; + break; + } + } + + if ( crystx_found == FALSE ) + { + fprintf( stderr, "[ERROR] improperly formatted BGF file (no CRYSTX keyword found). Terminating...\n" ); + exit( INVALID_INPUT ); + } + + fseek( bgf, 0, SEEK_SET ); + while ( fgets( line, MAX_LINE, bgf ) ) { /* read new line and tokenize it */ @@ -777,22 +811,6 @@ void Read_BGF( const char * const bgf_file, reax_system* system, control_params atom_cnt++; } - else if ( strncmp( tokens[0], "CRYSTX", 6 ) == 0 ) - { - sscanf( backup, BGF_CRYSTX_FORMAT, descriptor, - s_a, s_b, s_c, s_alpha, s_beta, s_gamma ); - - /* compute full volume tensor from the angles */ - Setup_Box( sstrtod( s_a, __FILE__, __LINE__ ), - sstrtod( s_b, __FILE__, __LINE__ ), - sstrtod( s_c, __FILE__, __LINE__ ), - sstrtod( s_alpha, __FILE__, __LINE__ ), - sstrtod( s_beta, __FILE__, __LINE__ ), - sstrtod( s_gamma, __FILE__, __LINE__ ), - &system->box ); - - crystx_found = TRUE; - } else if ( strncmp( tokens[0], "CONECT", 6 ) == 0 ) { if ( control->restrict_bonds ) @@ -835,12 +853,6 @@ void Read_BGF( const char * const bgf_file, reax_system* system, control_params exit( INVALID_INPUT ); } - if ( crystx_found == FALSE ) - { - fprintf( stderr, "[ERROR] improperly formatted BGF file (no CRYSTX keyword found). Terminating...\n" ); - exit( INVALID_INPUT ); - } - Deallocate_Tokenizer_Space( &line, &backup, &tokens, MAX_TOKENS ); sfclose( bgf, "Read_BGF::bgf" ); -- GitLab