+/* potential */
+#include "potentials/harmonic_oscillator.h"
+#include "potentials/lennard_jones.h"
+#include "potentials/albe.h"
+
+#ifdef TERSOFF_ORIG
+#include "potentials/tersoff_orig.h"
+#else
+#include "potentials/tersoff.h"
+#endif
+
+//#define INJECT 800
+#define INJECT 1
+#define NR_ATOMS 1
+#define R_C 1.5
+#define T_C 5.0
+//#define INJ_LENX (1*ALBE_LC_SIC)
+//#define INJ_LENY (1*ALBE_LC_SIC)
+//#define INJ_LENZ (1*ALBE_LC_SIC)
+#define INJ_LENX (1*ALBE_LC_SI)
+#define INJ_LENY (1*ALBE_LC_SI)
+#define INJ_LENZ (1*ALBE_LC_SI)
+#define INJ_TYPE_SILICON
+//#define INJ_TYPE_CARBON
+#define INJ_OFFSET (ALBE_LC_SI/8.0)
+#define RELAX_S 20
+
+#define LCNTX 5
+#define LCNTY 5
+#define LCNTZ 5
+#define PRERUN 10
+#define POSTRUN 2000
+
+#define R_TITLE "Silicon self-interstitial"
+#define LOG_E 10
+#define LOG_T 10
+#define LOG_P 10
+#define LOG_S 100
+#define LOG_V 20
+
+typedef struct s_hp {
+ int a_count; /* atom count */
+ u8 quit; /* quit mark */
+ int argc; /* arg count */
+ char **argv; /* args */
+} t_hp;
+
+int hook(void *moldyn,void *hook_params) {
+
+ t_moldyn *md;
+ t_3dvec r,v,dist;
+ double d;
+ unsigned char run;
+ int i,j;
+ t_atom *atom;
+ t_hp *hp;
+
+ md=moldyn;
+ hp=hook_params;
+
+ /* quit */
+ if(hp->quit)
+ return 0;
+
+ /* switch on t scaling */
+ if(md->schedule.count==0)
+ set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
+
+ /* last schedule add if there is enough carbon inside */
+ if(hp->a_count==(INJECT*NR_ATOMS)) {
+ hp->quit=1;
+ moldyn_add_schedule(md,POSTRUN,1.0);
+ return 0;
+ }
+
+ /* more relaxing time for too high temperatures */
+ if(md->t-md->t_ref>T_C) {
+ moldyn_add_schedule(md,RELAX_S,1.0);
+ return 0;
+ }
+
+ /* inject carbon atoms */
+ printf("injecting another %d atoms ... (-> %d / %d)\n",
+ NR_ATOMS,hp->a_count+NR_ATOMS,INJECT*NR_ATOMS);
+ for(j=0;j<NR_ATOMS;j++) {
+ run=1;
+ while(run) {
+ r.x=(rand_get_double(&(md->random))-0.5)*INJ_LENX;
+ r.x+=INJ_OFFSET;
+ r.y=(rand_get_double(&(md->random))-0.5)*INJ_LENY;
+ r.y+=INJ_OFFSET;
+ r.z=(rand_get_double(&(md->random))-0.5)*INJ_LENZ;
+ r.z+=INJ_OFFSET;
+ /* assume valid coordinates */
+ run=0;
+ for(i=0;i<md->count;i++) {
+ atom=&(md->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ d=v3_absolute_square(&dist);
+ /* reject coordinates */
+ if(d<R_C) {
+ run=1;
+ break;
+ }
+ }
+ }
+ v.x=0; v.y=0; v.z=0;
+#ifdef INJ_TYPE_CARBON
+ add_atom(md,C,M_C,1,
+#else
+ add_atom(md,SI,M_SI,0,
+#endif
+ ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
+ &r,&v);
+ }
+ hp->a_count+=NR_ATOMS;
+
+ /* add schedule for simulating injected atoms ;) */
+ moldyn_add_schedule(md,RELAX_S,1.0);
+
+ return 0;
+}
+