+/* 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 1
+#define NR_ATOMS 1
+#define R_C 2.0
+#define T_C 10.0
+#define LCNT 2
+
+typedef struct s_hp {
+ int a_count; /* atom count */
+ u8 quit; /* quit mark */
+} 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,5000,1.0);
+ return 0;
+ }
+
+ /* more relaxing time for too high temperatures */
+ if(md->t-md->t_ref>T_C) {
+ moldyn_add_schedule(md,10,1.0);
+ return 0;
+ }
+
+ /* inject carbon atoms */
+ printf("injecting another %d carbon 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)*md->dim.x*0.37;
+ r.y=(rand_get_double(&(md->random))-0.5)*md->dim.y*0.37;
+ r.z=(rand_get_double(&(md->random))-0.5)*md->dim.z*0.37;
+ /* 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;
+ add_atom(md,C,M_C,1,
+ 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,10,1.0);
+
+ return 0;
+}
+