-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtom.c
More file actions
89 lines (47 loc) · 3.91 KB
/
Copy pathAtom.c
File metadata and controls
89 lines (47 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stdheader.h"
#include "Atom.h"
#include "getboxdim.h"
Atom *atominfo(FILE *fp1,Box box,Ljcoeff *lj, int natoms) {
size_t nbytes = 100;
char *my_string=NULL;
int i;
Atom *atom=(Atom *) malloc(sizeof(Atom));
atom->id = (int *) malloc(sizeof(int) *natoms);
atom->type =(int *) malloc(sizeof(int) * natoms);
atom->x = (double *) malloc(sizeof(double) * natoms);
atom->y = (double *) malloc(sizeof(double) * natoms);
atom->z = (double *) malloc(sizeof(double) * natoms);
atom->q = (double *) malloc(sizeof(double) * natoms);
atom->eps=(double *) malloc(sizeof(double) * natoms);
atom->sigma=(double *) malloc(sizeof(double) * natoms);
atom->natoms=natoms;
for (i = 0; i < natoms; i++) {
atom->eps[i]=lj->eps[i];
atom->sigma[i]=lj->sigma[i];
getline(&my_string, &nbytes, fp1);
sscanf(my_string, "%d %d %lf %lf %lf %lf\n", &atom->id[i],&atom->type[i],&atom->x[i],
&atom->y[i], &atom->z[i], &atom->q[i]);
if((atom->x[i] - box.xlo) < 0) {atom->x[i]= atom->x[i]+(box.xhi-box.xlo);}//add box length
if((atom->x[i] - box.xhi) >= 0) {atom->x[i]= atom->x[i]-(box.xhi-box.xlo);}//subtract box length
if((atom->y[i] - box.ylo) < 0) {atom->y[i]= atom->y[i]+(box.yhi-box.ylo);}
if((atom->y[i] - box.yhi) >= 0) {atom->y[i]= atom->y[i]-(box.yhi-box.ylo);}
if((atom->z[i] - box.zlo) < 0) {atom->z[i]= atom->z[i]+(box.zhi-box.zlo);}
if((atom->z[i] - box.zhi) >= 0) {atom->z[i]= atom->z[i]-(box.zhi-box.zlo);}
}
// fprintf(fp3,"%d %lf %lf %lf\n",atom->id[i],atom->x[i],atom->y[i],atom->z[i]);
// fprintf("%d %lf %lf %lf %lf\n",atom->id[i],atom->x[i],atom->y[i],atom->z[i],(0.5)*atom->sigma[i]);
// printf("%d %lf %lf %lf %lf\n",atom->type[i],atom->x[i],atom->y[i],atom->z[i],atom->sigma[i]);
return atom;
}
void free_atom(Atom *atom)
{
free(atom->x);
free(atom->type);
free(atom->id);
free(atom->y);
free(atom->z);
free(atom->q);
free(atom->eps);
free(atom->sigma);
free(atom);
}