Newer
Older
/*----------------------------------------------------------------------
SerialReax - Reax Force Field Simulator
Copyright (2010) Purdue University
Hasan Metin Aktulga, haktulga@cs.purdue.edu
Joseph Fogarty, jcfogart@mail.usf.edu
Sagar Pandit, pandit@usf.edu
Ananth Y Grama, ayg@cs.purdue.edu
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
See the GNU General Public License for more details:
<http://www.gnu.org/licenses/>.
----------------------------------------------------------------------*/
Kurt A. O'Hearn
committed
#include "spuremd.h"
Kurt A. O'Hearn
committed
#include "allocate.h"
Kurt A. O'Hearn
committed
#include "box.h"
Kurt A. O'Hearn
committed
#include "control.h"
#include "ffield.h"
Kurt A. O'Hearn
committed
#include "io_tools.h"
Kurt A. O'Hearn
committed
#include "geo_tools.h"
Kurt A. O'Hearn
committed
#include "reset_tools.h"
#include "tool_box.h"
Kurt A. O'Hearn
committed
/* Handles additional entire geometry calculations after
* perturbing atom positions during a simulation step
*/
static void Post_Evolve( reax_system * const system, control_params * const control,
simulation_data * const data, static_storage * const workspace,
Kurt A. O'Hearn
committed
reax_list ** const lists, output_controls * const out_control )
int i;
rvec diff, cross;
/* remove rotational and translational velocity of the center of mass */
Kurt A. O'Hearn
committed
if ( control->ensemble != NVE && control->remove_CoM_vel > 0
Kurt A. O'Hearn
committed
&& data->step % control->remove_CoM_vel == 0 )
Kurt A. O'Hearn
committed
Compute_Center_of_Mass( system, data );
Kurt A. O'Hearn
committed
/* remove translational */
rvec_ScaledAdd( system->atoms[i].v, -1.0, data->vcm );
Kurt A. O'Hearn
committed
/* remove rotational */
rvec_ScaledSum( diff, 1.0, system->atoms[i].x, -1.0, data->xcm );
Kurt A. O'Hearn
committed
rvec_ScaledAdd( system->atoms[i].v, -1.0, cross );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( control->ensemble == NVE )
{
Compute_Kinetic_Energy( system, data );
}
Kurt A. O'Hearn
committed
if ( (out_control->log_update_freq > 0
&& data->step % out_control->log_update_freq == 0)
Kurt A. O'Hearn
committed
|| (out_control->write_steps > 0
&& data->step % out_control->write_steps == 0) )
{
Kurt A. O'Hearn
committed
Compute_Total_Energy( data );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
if ( control->compute_pressure == TRUE && control->ensemble != sNPT
&& control->ensemble != iNPT && control->ensemble != aNPT )
{
Compute_Pressure_Isotropic( system, control, data, out_control );
}
Kurt A. O'Hearn
committed
/* Parse input files
*
* geo_file: file containing geometry info of the structure to simulate
* ffield_file: file containing force field parameters
* control_file: file containing simulation parameters
*/
static void Read_Input_Files( const char * const geo_file,
const char * const ffield_file, const char * const control_file,
reax_system * const system, control_params * const control,
simulation_data * const data, static_storage * const workspace,
Kurt A. O'Hearn
committed
output_controls * const out_control )
Kurt A. O'Hearn
committed
if ( ffield_file != NULL )
Kurt A. O'Hearn
committed
Read_Force_Field( ffield_file, system, &system->reax_param );
Kurt A. O'Hearn
committed
if ( control_file != NULL )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Read_Control_File( control_file, system, control, out_control );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
if ( geo_file != NULL )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
if ( control->geo_format == CUSTOM )
{
Read_Geo( geo_file, system, control, data, workspace );
}
else if ( control->geo_format == PDB )
{
Read_PDB( geo_file, system, control, data, workspace );
}
else if ( control->geo_format == BGF )
{
Read_BGF( geo_file, system, control, data, workspace );
}
else if ( control->geo_format == ASCII_RESTART )
{
Read_ASCII_Restart( geo_file, system, control, data, workspace );
control->restart = TRUE;
}
else if ( control->geo_format == BINARY_RESTART )
{
Read_Binary_Restart( geo_file, system, control, data, workspace );
control->restart = TRUE;
}
else
{
fprintf( stderr, "[ERROR] unknown geo file format. terminating!\n" );
exit( INVALID_GEO );
}
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#if defined(DEBUG_FOCUS)
Print_Box( &system->box, stderr );
#endif
}
/* Allocate top-level data structures and parse input files
* for the first simulation
*
* qm_num_atoms: num. atoms in the QM region
* qm_types: element types for QM atoms
* qm_pos_x: x-coordinate of QM atom positions, in Angstroms
* qm_pos_y: y-coordinate of QM atom positions, in Angstroms
* qm_pos_z: z-coordinate of QM atom positions, in Angstroms
* mm_num_atoms: num. atoms in the MM region
* mm_types: element types for MM atoms
* mm_pos_x: x-coordinate of MM atom positions, in Angstroms
* mm_pos_y: y-coordinate of MM atom positions, in Angstroms
* mm_pos_z: z-coordinate of MM atom positions, in Angstroms
* mm_q: charge of MM atom, in Coulombs
* sim_box: simulation box information, where the entries are
* - box length per dimension (3 entries)
* - angles per dimension (3 entries)
* ffield_file: file containing force field parameters
* control_file: file containing simulation parameters
*/
void * setup_qmmm_( int qm_num_atoms, const int * const qm_types,
const double * const qm_pos_x, const double * const qm_pos_y,
const double * const qm_pos_z,
int mm_num_atoms, const int * const mm_types,
const double * const mm_pos_x, const double * const mm_pos_y,
const double * const mm_pos_z, const double * const mm_q,
const double * const sim_box,
const char * const ffield_file,
const char * const control_file )
{
int i;
// char atom_name[9];
rvec x;
spuremd_handle *spmd_handle;
/* top-level allocation */
spmd_handle = (spuremd_handle*) smalloc( sizeof(spuremd_handle),
"setup::spmd_handle" );
/* second-level allocations */
spmd_handle->system = smalloc( sizeof(reax_system),
"Setup::spmd_handle->system" );
spmd_handle->system->prealloc_allocated = FALSE;
spmd_handle->system->ffield_params_allocated = FALSE;
spmd_handle->system->g.allocated = FALSE;
spmd_handle->control = smalloc( sizeof(control_params),
"Setup::spmd_handle->control" );
spmd_handle->data = smalloc( sizeof(simulation_data),
"Setup::spmd_handle->data" );
spmd_handle->workspace = smalloc( sizeof(static_storage),
"Setup::spmd_handle->workspace" );
spmd_handle->workspace->H.allocated = FALSE;
spmd_handle->workspace->H_full.allocated = FALSE;
spmd_handle->workspace->H_sp.allocated = FALSE;
spmd_handle->workspace->H_p.allocated = FALSE;
spmd_handle->workspace->H_spar_patt.allocated = FALSE;
spmd_handle->workspace->H_spar_patt_full.allocated = FALSE;
spmd_handle->workspace->H_app_inv.allocated = FALSE;
spmd_handle->workspace->L.allocated = FALSE;
spmd_handle->workspace->U.allocated = FALSE;
spmd_handle->lists = smalloc( sizeof(reax_list *) * LIST_N,
"Setup::spmd_handle->lists" );
for ( i = 0; i < LIST_N; ++i )
Kurt A. O'Hearn
committed
spmd_handle->lists[i] = smalloc( sizeof(reax_list),
"Setup::spmd_handle->lists[i]" );
spmd_handle->lists[i]->allocated = FALSE;
Kurt A. O'Hearn
committed
spmd_handle->out_control = smalloc( sizeof(output_controls),
"Setup::spmd_handle->out_control" );
spmd_handle->output_enabled = FALSE;
spmd_handle->realloc = TRUE;
spmd_handle->callback = NULL;
spmd_handle->data->sim_id = 0;
spmd_handle->system->N_qm = qm_num_atoms;
spmd_handle->system->N_mm = mm_num_atoms;
Kurt A. O'Hearn
committed
spmd_handle->system->N = qm_num_atoms + mm_num_atoms;
PreAllocate_Space( spmd_handle->system, spmd_handle->control,
spmd_handle->workspace, spmd_handle->system->N );
Setup_Box( sim_box[0], sim_box[1], sim_box[2],
sim_box[3], sim_box[4], sim_box[5],
&spmd_handle->system->box );
for ( i = 0; i < qm_num_atoms; ++i )
Kurt A. O'Hearn
committed
x[0] = qm_pos_x[i];
x[1] = qm_pos_y[i];
x[2] = qm_pos_z[i];
Fit_to_Periodic_Box( &spmd_handle->system->box, x );
spmd_handle->workspace->orig_id[i] = i + 1;
// spmd_handle->system->atoms[i].type = Get_Atom_Type( &system->reax_param,
// element, sizeof(element) );
spmd_handle->system->atoms[i].type = qm_types[i];
// strncpy( spmd_handle->system->atoms[i].name, atom_name,
// sizeof(spmd_handle->system->atoms[i].name) - 1 );
// spmd_handle->system->atoms[i].name[sizeof(spmd_handle->system->atoms[i].name) - 1] = '\0';
rvec_Copy( spmd_handle->system->atoms[i].x, x );
rvec_MakeZero( spmd_handle->system->atoms[i].v );
rvec_MakeZero( spmd_handle->system->atoms[i].f );
spmd_handle->system->atoms[i].q = 0.0;
// mask[i] = 1;
Kurt A. O'Hearn
committed
for ( i = qm_num_atoms; i < qm_num_atoms + mm_num_atoms; ++i )
Kurt A. O'Hearn
committed
x[0] = mm_pos_x[i - qm_num_atoms];
x[1] = mm_pos_y[i - qm_num_atoms];
x[2] = mm_pos_z[i - qm_num_atoms];
Fit_to_Periodic_Box( &spmd_handle->system->box, x );
spmd_handle->workspace->orig_id[i] = i + 1;
// spmd_handle->system->atoms[i].type = Get_Atom_Type( &system->reax_param,
// element, sizeof(element) );
spmd_handle->system->atoms[i].type = mm_types[i - qm_num_atoms];
// strncpy( spmd_handle->system->atoms[i].name, atom_name,
// sizeof(spmd_handle->system->atoms[i].name) - 1 );
// spmd_handle->system->atoms[i].name[sizeof(spmd_handle->system->atoms[i].name) - 1] = '\0';
rvec_Copy( spmd_handle->system->atoms[i].x, x );
rvec_MakeZero( spmd_handle->system->atoms[i].v );
rvec_MakeZero( spmd_handle->system->atoms[i].f );
spmd_handle->system->atoms[i].q = mm_q[i - qm_num_atoms];
// mask[i] = 0;
Kurt A. O'Hearn
committed
Read_Input_Files( NULL, ffield_file, control_file,
spmd_handle->system, spmd_handle->control,
spmd_handle->data, spmd_handle->workspace,
spmd_handle->out_control );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
spmd_handle->system->N_max = (int) CEIL( SAFE_ZONE * spmd_handle->system->N );
return (void *) spmd_handle;
Kurt A. O'Hearn
committed
/* Allocate top-level data structures and parse input files
* for the first simulation
*
* geo_file: file containing geometry info of the structure to simulate
* ffield_file: file containing force field parameters
* control_file: file containing simulation parameters
*/
Kurt A. O'Hearn
committed
void * setup( const char * const geo_file, const char * const ffield_file,
Kurt A. O'Hearn
committed
const char * const control_file )
int i;
Kurt A. O'Hearn
committed
spuremd_handle *spmd_handle;
/* top-level allocation */
spmd_handle = (spuremd_handle*) smalloc( sizeof(spuremd_handle),
"setup::spmd_handle" );
/* second-level allocations */
spmd_handle->system = smalloc( sizeof(reax_system),
Kurt A. O'Hearn
committed
"Setup::spmd_handle->system" );
Kurt A. O'Hearn
committed
spmd_handle->system->prealloc_allocated = FALSE;
spmd_handle->system->ffield_params_allocated = FALSE;
Kurt A. O'Hearn
committed
spmd_handle->system->g.allocated = FALSE;
spmd_handle->control = smalloc( sizeof(control_params),
Kurt A. O'Hearn
committed
"Setup::spmd_handle->control" );
Kurt A. O'Hearn
committed
spmd_handle->data = smalloc( sizeof(simulation_data),
Kurt A. O'Hearn
committed
"Setup::spmd_handle->data" );
Kurt A. O'Hearn
committed
spmd_handle->workspace = smalloc( sizeof(static_storage),
Kurt A. O'Hearn
committed
"Setup::spmd_handle->workspace" );
Kurt A. O'Hearn
committed
spmd_handle->workspace->H.allocated = FALSE;
spmd_handle->workspace->H_full.allocated = FALSE;
spmd_handle->workspace->H_sp.allocated = FALSE;
spmd_handle->workspace->H_p.allocated = FALSE;
spmd_handle->workspace->H_spar_patt.allocated = FALSE;
spmd_handle->workspace->H_spar_patt_full.allocated = FALSE;
spmd_handle->workspace->H_app_inv.allocated = FALSE;
spmd_handle->workspace->L.allocated = FALSE;
spmd_handle->workspace->U.allocated = FALSE;
spmd_handle->lists = smalloc( sizeof(reax_list *) * LIST_N,
Kurt A. O'Hearn
committed
"Setup::spmd_handle->lists" );
for ( i = 0; i < LIST_N; ++i )
{
spmd_handle->lists[i] = smalloc( sizeof(reax_list),
"Setup::spmd_handle->lists[i]" );
spmd_handle->lists[i]->allocated = FALSE;
}
spmd_handle->out_control = smalloc( sizeof(output_controls),
Kurt A. O'Hearn
committed
"Setup::spmd_handle->out_control" );
spmd_handle->output_enabled = TRUE;
Kurt A. O'Hearn
committed
spmd_handle->realloc = TRUE;
Kurt A. O'Hearn
committed
spmd_handle->callback = NULL;
Kurt A. O'Hearn
committed
spmd_handle->data->sim_id = 0;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Read_Input_Files( geo_file, ffield_file, control_file,
Kurt A. O'Hearn
committed
spmd_handle->system, spmd_handle->control,
spmd_handle->data, spmd_handle->workspace,
Kurt A. O'Hearn
committed
spmd_handle->out_control );
Kurt A. O'Hearn
committed
spmd_handle->system->N_max = (int) CEIL( SAFE_ZONE * spmd_handle->system->N );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
return (void *) spmd_handle;
Kurt A. O'Hearn
committed
/* Setup callback function to be run after each simulation step
*
* handle: pointer to wrapper struct with top-level data structures
* callback: function pointer to attach for callback
Kurt A. O'Hearn
committed
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
Kurt A. O'Hearn
committed
*/
Kurt A. O'Hearn
committed
int setup_callback( const void * const handle, const callback_function callback )
{
int ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL && callback != NULL )
{
spmd_handle = (spuremd_handle*) handle;
spmd_handle->callback = callback;
ret = SPUREMD_SUCCESS;
}
return ret;
}
Kurt A. O'Hearn
committed
/* Run the simulation according to the prescribed parameters
*
* handle: pointer to wrapper struct with top-level data structures
Kurt A. O'Hearn
committed
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
Kurt A. O'Hearn
committed
*/
Kurt A. O'Hearn
committed
int simulate( const void * const handle )
Kurt A. O'Hearn
committed
int steps, ret;
Kurt A. O'Hearn
committed
evolve_function Evolve;
Kurt A. O'Hearn
committed
spuremd_handle *spmd_handle;
Kurt A. O'Hearn
committed
ret = SPUREMD_FAILURE;
Kurt A. O'Hearn
committed
if ( handle != NULL )
Kurt A. O'Hearn
committed
spmd_handle = (spuremd_handle*) handle;
Initialize( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists,
spmd_handle->out_control, &Evolve,
Kurt A. O'Hearn
committed
spmd_handle->output_enabled,
Kurt A. O'Hearn
committed
spmd_handle->realloc );
Kurt A. O'Hearn
committed
spmd_handle->realloc = FALSE;
Kurt A. O'Hearn
committed
/* compute f_0 */
Kurt A. O'Hearn
committed
Reset( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Generate_Neighbor_Lists( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
Compute_Forces( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control,
spmd_handle->realloc );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Compute_Kinetic_Energy( spmd_handle->system, spmd_handle->data );
Kurt A. O'Hearn
committed
if ( spmd_handle->control->compute_pressure == TRUE && spmd_handle->control->ensemble != sNPT
&& spmd_handle->control->ensemble != iNPT && spmd_handle->control->ensemble != aNPT )
{
Compute_Pressure_Isotropic( spmd_handle->system, spmd_handle->control,
spmd_handle->data, spmd_handle->out_control );
}
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE || spmd_handle->callback != NULL )
Kurt A. O'Hearn
committed
{
if ( ((spmd_handle->out_control->log_update_freq > 0
&& spmd_handle->data->step % spmd_handle->out_control->log_update_freq == 0)
Kurt A. O'Hearn
committed
|| (spmd_handle->out_control->write_steps > 0
Kurt A. O'Hearn
committed
&& spmd_handle->data->step % spmd_handle->out_control->write_steps == 0))
|| spmd_handle->callback != NULL )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Compute_Total_Energy( spmd_handle->data );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE )
{
Kurt A. O'Hearn
committed
Output_Results( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
Check_Energy( spmd_handle->data );
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE )
{
if ( spmd_handle->out_control->write_steps > 0
&& spmd_handle->data->step % spmd_handle->out_control->write_steps == 0 )
{
Write_PDB( spmd_handle->system, spmd_handle->lists[BONDS], spmd_handle->data,
spmd_handle->control, spmd_handle->workspace, spmd_handle->out_control );
}
}
Kurt A. O'Hearn
committed
if ( spmd_handle->callback != NULL )
{
spmd_handle->callback( spmd_handle->system->N, spmd_handle->system->atoms,
spmd_handle->data );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
//}
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
for ( ++spmd_handle->data->step; spmd_handle->data->step <= spmd_handle->control->nsteps; spmd_handle->data->step++ )
{
Kurt A. O'Hearn
committed
if ( spmd_handle->control->T_mode != 0 )
Kurt A. O'Hearn
committed
{
Temperature_Control( spmd_handle->control, spmd_handle->data,
spmd_handle->out_control );
}
Evolve( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Post_Evolve( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE )
{
Output_Results( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
}
Check_Energy( spmd_handle->data );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE )
{
Kurt A. O'Hearn
committed
steps = spmd_handle->data->step - spmd_handle->data->prev_steps;
Kurt A. O'Hearn
committed
Analysis( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( spmd_handle->out_control->restart_freq > 0
&& steps % spmd_handle->out_control->restart_freq == 0 )
{
Write_Restart( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->out_control );
}
if ( spmd_handle->out_control->write_steps > 0
&& steps % spmd_handle->out_control->write_steps == 0 )
{
Write_PDB( spmd_handle->system, spmd_handle->lists[BONDS], spmd_handle->data,
spmd_handle->control, spmd_handle->workspace, spmd_handle->out_control );
}
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
if ( spmd_handle->callback != NULL )
{
spmd_handle->callback( spmd_handle->system->N, spmd_handle->system->atoms,
spmd_handle->data );
Kurt A. O'Hearn
committed
}
}
Kurt A. O'Hearn
committed
spmd_handle->data->timing.end = Get_Time( );
spmd_handle->data->timing.elapsed = Get_Timing_Info( spmd_handle->data->timing.start );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( spmd_handle->output_enabled == TRUE )
{
fprintf( spmd_handle->out_control->log, "total: %.2f secs\n", spmd_handle->data->timing.elapsed );
}
Kurt A. O'Hearn
committed
ret = SPUREMD_SUCCESS;
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
return ret;
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
/* Deallocate all data structures post-simulation
*
* handle: pointer to wrapper struct with top-level data structures
Kurt A. O'Hearn
committed
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
Kurt A. O'Hearn
committed
*/
Kurt A. O'Hearn
committed
int cleanup( const void * const handle )
Kurt A. O'Hearn
committed
{
int i, ret;
Kurt A. O'Hearn
committed
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
Finalize( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control,
Kurt A. O'Hearn
committed
spmd_handle->output_enabled, FALSE );
Kurt A. O'Hearn
committed
sfree( spmd_handle->out_control, "cleanup::spmd_handle->out_control" );
for ( i = 0; i < LIST_N; ++i )
{
sfree( spmd_handle->lists[i], "cleanup::spmd_handle->lists[i]" );
}
Kurt A. O'Hearn
committed
sfree( spmd_handle->lists, "cleanup::spmd_handle->lists" );
sfree( spmd_handle->workspace, "cleanup::spmd_handle->workspace" );
sfree( spmd_handle->data, "cleanup::spmd_handle->data" );
sfree( spmd_handle->control, "cleanup::spmd_handle->control" );
sfree( spmd_handle->system, "cleanup::spmd_handle->system" );
sfree( spmd_handle, "cleanup::spmd_handle" );
ret = SPUREMD_SUCCESS;
}
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
return ret;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/* Reset for the next simulation by parsing input files and triggering
* reallocation if more space is needed
*
* handle: pointer to wrapper struct with top-level data structures
* qm_num_atoms: num. atoms in the QM region
* qm_types: element types for QM atoms
* qm_pos_x: x-coordinate of QM atom positions, in Angstroms
* qm_pos_y: y-coordinate of QM atom positions, in Angstroms
* qm_pos_z: z-coordinate of QM atom positions, in Angstroms
* mm_num_atoms: num. atoms in the MM region
* mm_types: element types for MM atoms
* mm_pos_x: x-coordinate of MM atom positions, in Angstroms
* mm_pos_y: y-coordinate of MM atom positions, in Angstroms
* mm_pos_z: z-coordinate of MM atom positions, in Angstroms
* mm_q: charge of MM atom, in Coulombs
* sim_box: simulation box information, where the entries are
* - box length per dimension (3 entries)
* - angles per dimension (3 entries)
* ffield_file: file containing force field parameters
* control_file: file containing simulation parameters
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int reset_qmmm_( const void * const handle,
int qm_num_atoms, const int * const qm_types,
const double * const qm_pos_x, const double * const qm_pos_y,
const double * const qm_pos_z,
int mm_num_atoms, const int * const mm_types,
const double * const mm_pos_x, const double * const mm_pos_y,
const double * const mm_pos_z, const double * const mm_q,
const double * const sim_box,
const char * const ffield_file, const char * const control_file )
{
int i, ret;
rvec x;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
/* close files used in previous simulation */
if ( spmd_handle->output_enabled == TRUE )
{
Finalize_Out_Controls( spmd_handle->system, spmd_handle->control,
spmd_handle->workspace, spmd_handle->out_control );
}
spmd_handle->realloc = FALSE;
spmd_handle->data->sim_id++;
spmd_handle->system->N_qm = qm_num_atoms;
spmd_handle->system->N_mm = mm_num_atoms;
Kurt A. O'Hearn
committed
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
spmd_handle->system->N = qm_num_atoms + mm_num_atoms;
PreAllocate_Space( spmd_handle->system, spmd_handle->control,
spmd_handle->workspace, spmd_handle->system->N );
Setup_Box( sim_box[0], sim_box[1], sim_box[2],
sim_box[3], sim_box[4], sim_box[5],
&spmd_handle->system->box );
for ( i = 0; i < qm_num_atoms; ++i )
{
x[0] = qm_pos_x[i];
x[1] = qm_pos_y[i];
x[2] = qm_pos_z[i];
Fit_to_Periodic_Box( &spmd_handle->system->box, x );
spmd_handle->workspace->orig_id[i] = i + 1;
// spmd_handle->system->atoms[i].type = Get_Atom_Type( &system->reax_param,
// element, sizeof(element) );
spmd_handle->system->atoms[i].type = qm_types[i];
// strncpy( spmd_handle->system->atoms[i].name, atom_name,
// sizeof(spmd_handle->system->atoms[i].name) - 1 );
// spmd_handle->system->atoms[i].name[sizeof(spmd_handle->system->atoms[i].name) - 1] = '\0';
rvec_Copy( spmd_handle->system->atoms[i].x, x );
rvec_MakeZero( spmd_handle->system->atoms[i].v );
rvec_MakeZero( spmd_handle->system->atoms[i].f );
spmd_handle->system->atoms[i].q = 0.0;
// mask[i] = 1;
}
for ( i = qm_num_atoms; i < qm_num_atoms + mm_num_atoms; ++i )
{
x[0] = mm_pos_x[i - qm_num_atoms];
x[1] = mm_pos_y[i - qm_num_atoms];
x[2] = mm_pos_z[i - qm_num_atoms];
Fit_to_Periodic_Box( &spmd_handle->system->box, x );
spmd_handle->workspace->orig_id[i] = i + 1;
// spmd_handle->system->atoms[i].type = Get_Atom_Type( &system->reax_param,
// element, sizeof(element) );
spmd_handle->system->atoms[i].type = mm_types[i - qm_num_atoms];
// strncpy( spmd_handle->system->atoms[i].name, atom_name,
// sizeof(spmd_handle->system->atoms[i].name) - 1 );
// spmd_handle->system->atoms[i].name[sizeof(spmd_handle->system->atoms[i].name) - 1] = '\0';
rvec_Copy( spmd_handle->system->atoms[i].x, x );
rvec_MakeZero( spmd_handle->system->atoms[i].v );
rvec_MakeZero( spmd_handle->system->atoms[i].f );
spmd_handle->system->atoms[i].q = mm_q[i - qm_num_atoms];
// mask[i] = 0;
}
Read_Input_Files( NULL, ffield_file, control_file,
spmd_handle->system, spmd_handle->control,
spmd_handle->data, spmd_handle->workspace,
spmd_handle->out_control );
if ( spmd_handle->system->N > spmd_handle->system->N_max )
{
/* deallocate everything which needs more space
* (i.e., structures whose space is a function of the number of atoms),
* except for data structures allocated while parsing input files */
Finalize( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control,
spmd_handle->output_enabled, TRUE );
spmd_handle->system->N_max = (int) CEIL( SAFE_ZONE * spmd_handle->system->N );
spmd_handle->realloc = TRUE;
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
Kurt A. O'Hearn
committed
/* Reset for the next simulation by parsing input files and triggering
* reallocation if more space is needed
*
* handle: pointer to wrapper struct with top-level data structures
* geo_file: file containing geometry info of the structure to simulate
* ffield_file: file containing force field parameters
* control_file: file containing simulation parameters
Kurt A. O'Hearn
committed
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
Kurt A. O'Hearn
committed
*/
int reset( const void * const handle, const char * const geo_file,
const char * const ffield_file, const char * const control_file )
{
int ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
/* close files used in previous simulation */
if ( spmd_handle->output_enabled == TRUE )
{
Finalize_Out_Controls( spmd_handle->system, spmd_handle->control,
spmd_handle->workspace, spmd_handle->out_control );
}
Kurt A. O'Hearn
committed
spmd_handle->realloc = FALSE;
spmd_handle->data->sim_id++;
Read_Input_Files( geo_file, ffield_file, control_file,
spmd_handle->system, spmd_handle->control,
spmd_handle->data, spmd_handle->workspace,
Kurt A. O'Hearn
committed
spmd_handle->out_control );
Kurt A. O'Hearn
committed
if ( spmd_handle->system->N > spmd_handle->system->N_max )
{
/* deallocate everything which needs more space
* (i.e., structures whose space is a function of the number of atoms),
* except for data structures allocated while parsing input files */
Finalize( spmd_handle->system, spmd_handle->control, spmd_handle->data,
spmd_handle->workspace, spmd_handle->lists, spmd_handle->out_control,
spmd_handle->output_enabled, TRUE );
spmd_handle->system->N_max = (int) CEIL( SAFE_ZONE * spmd_handle->system->N );
spmd_handle->realloc = TRUE;
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
/* Getter for atom positions in QMMM mode
*
* handle: pointer to wrapper struct with top-level data structures
* qm_pos_x: x-coordinate of QM atom positions, in Angstroms (allocated by caller)
* qm_pos_y: y-coordinate of QM atom positions, in Angstroms (allocated by caller)
* qm_pos_z: z-coordinate of QM atom positions, in Angstroms (allocated by caller)
* mm_pos_x: x-coordinate of MM atom positions, in Angstroms (allocated by caller)
* mm_pos_y: y-coordinate of MM atom positions, in Angstroms (allocated by caller)
* mm_pos_z: z-coordinate of MM atom positions, in Angstroms (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int get_atom_positions_qmmm_( const void * const handle, double * const qm_pos_x,
double * const qm_pos_y, double * const qm_pos_z, double * const mm_pos_x,
double * const mm_pos_y, double * const mm_pos_z )
{
int i, ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
for ( i = 0; i < spmd_handle->system->N_qm; ++i )
{
qm_pos_x[i] = spmd_handle->system->atoms[i].x[0];
qm_pos_y[i] = spmd_handle->system->atoms[i].x[1];
qm_pos_z[i] = spmd_handle->system->atoms[i].x[2];
}
for ( i = spmd_handle->system->N_qm; i < spmd_handle->system->N; ++i )
{
mm_pos_x[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].x[0];
mm_pos_y[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].x[1];
mm_pos_z[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].x[2];
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
/* Getter for atom velocities in QMMM mode
*
* handle: pointer to wrapper struct with top-level data structures
* qm_vel_x: x-coordinate of QM atom velocities, in Angstroms / ps (allocated by caller)
* qm_vel_y: y-coordinate of QM atom velocities, in Angstroms / ps (allocated by caller)
* qm_vel_z: z-coordinate of QM atom velocities, in Angstroms / ps (allocated by caller)
* mm_vel_x: x-coordinate of MM atom velocities, in Angstroms / ps (allocated by caller)
* mm_vel_y: y-coordinate of MM atom velocities, in Angstroms / ps (allocated by caller)
* mm_vel_z: z-coordinate of MM atom velocities, in Angstroms / ps (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int get_atom_velocities_qmmm_( const void * const handle, double * const qm_vel_x,
double * const qm_vel_y, double * const qm_vel_z, double * const mm_vel_x,
double * const mm_vel_y, double * const mm_vel_z )
{
int i, ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
for ( i = 0; i < spmd_handle->system->N_qm; ++i )
{
qm_vel_x[i] = spmd_handle->system->atoms[i].v[0];
qm_vel_y[i] = spmd_handle->system->atoms[i].v[1];
qm_vel_z[i] = spmd_handle->system->atoms[i].v[2];
}
for ( i = spmd_handle->system->N_qm; i < spmd_handle->system->N; ++i )
{
mm_vel_x[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].v[0];
mm_vel_y[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].v[1];
mm_vel_z[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].v[2];
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
/* Getter for atom forces in QMMM mode
*
* handle: pointer to wrapper struct with top-level data structures
* qm_f_x: x-coordinate of QM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
* qm_f_y: y-coordinate of QM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
* qm_f_z: z-coordinate of QM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
* mm_f_x: x-coordinate of MM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
* mm_f_y: y-coordinate of MM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
* mm_f_z: z-coordinate of MM atom forces, in Angstroms * Daltons / ps^2 (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int get_atom_forces_qmmm_( const void * const handle, double * const qm_f_x,
double * const qm_f_y, double * const qm_f_z, double * const mm_f_x,
double * const mm_f_y, double * const mm_f_z )
{
int i, ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
for ( i = 0; i < spmd_handle->system->N_qm; ++i )
{
qm_f_x[i] = spmd_handle->system->atoms[i].f[0];
qm_f_y[i] = spmd_handle->system->atoms[i].f[1];
qm_f_z[i] = spmd_handle->system->atoms[i].f[2];
}
for ( i = spmd_handle->system->N_qm; i < spmd_handle->system->N; ++i )
{
mm_f_x[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].f[0];
mm_f_y[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].f[1];
mm_f_z[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].f[2];
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
/* Getter for atom charges in QMMM mode
*
* handle: pointer to wrapper struct with top-level data structures
* qm_q: QM atom charges, in Coulombs (allocated by caller)
* mm_q: MM atom charges, in Coulombs (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int get_atom_charges_qmmm_( const void * const handle, double * const qm_q,
double * const mm_q )
{
int i, ret;
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
for ( i = 0; i < spmd_handle->system->N_qm; ++i )
{
qm_q[i] = spmd_handle->system->atoms[i].q;
}
for ( i = spmd_handle->system->N_qm; i < spmd_handle->system->N; ++i )
{
mm_q[i - spmd_handle->system->N_qm] = spmd_handle->system->atoms[i].q;
}
ret = SPUREMD_SUCCESS;
}
return ret;
}
/* Getter for atom positions
Kurt A. O'Hearn
committed
*
* handle: pointer to wrapper struct with top-level data structures
Kurt A. O'Hearn
committed
* pos_x: x-coordinate of atom positions, in Angstroms (allocated by caller)
* pos_y: y-coordinate of atom positions, in Angstroms (allocated by caller)
* pos_z: z-coordinate of atom positions, in Angstroms (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
Kurt A. O'Hearn
committed
*/
int get_atom_positions( const void * const handle, double * const pos_x,
double * const pos_y, double * const pos_z )
Kurt A. O'Hearn
committed
{
int i, ret;
Kurt A. O'Hearn
committed
spuremd_handle *spmd_handle;
ret = SPUREMD_FAILURE;
Kurt A. O'Hearn
committed
if ( handle != NULL )
{
spmd_handle = (spuremd_handle*) handle;
for ( i = 0; i < spmd_handle->system->N; ++i )
{
pos_x[i] = spmd_handle->system->atoms[i].x[0];
pos_y[i] = spmd_handle->system->atoms[i].x[1];
pos_z[i] = spmd_handle->system->atoms[i].x[2];
}
ret = SPUREMD_SUCCESS;
Kurt A. O'Hearn
committed
}
return ret;
}
Kurt A. O'Hearn
committed
/* Getter for atom velocities
*
* handle: pointer to wrapper struct with top-level data structures
* vel_x: x-coordinate of atom velocities, in Angstroms / ps (allocated by caller)
* vel_y: y-coordinate of atom velocities, in Angstroms / ps (allocated by caller)
* vel_z: z-coordinate of atom velocities, in Angstroms / ps (allocated by caller)
*
* returns: SPUREMD_SUCCESS upon success, SPUREMD_FAILURE otherwise
*/
int get_atom_velocities( const void * const handle, double * const vel_x,
double * const vel_y, double * const vel_z )
{
int i, ret;
spuremd_handle *spmd_handle;