-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.h
147 lines (128 loc) · 3.25 KB
/
node.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
142
143
144
145
146
147
#ifndef NODE_H
#define NODE_H
#include <iostream>
#include <vector>
#include <fstream>
#include "stringtools.h"
using namespace std;
template<class T>
class Node
{
public:
Node();
Node(const T& item, Node<T>* ptrnext = NULL);
T data;
// access to the next node
Node<T>* NextNode();
// list modification methods
void InsertAfter(Node<T>* p);
Node<T>* DeleteAfter();
Node<T> * GetNode(const T& item, Node<T>* nextptr = NULL);
// private:
Node<T> * next;
};
struct record
{
string gene;
double HOMO;
double LUMO;
double MW;
};
struct GANode
{
// int charge;
// int multi;
size_t natoms;
// int ntemp; /*based on which template, ref=0*/
vector<double> coords;
vector<string> anames;
string gene; /*R code: save as |V1_code|V2_code|...|*/
string comment; /*name of the molecule? use as filename?*/
double score;
double score_ETL;
double score_HTL;
double HOMO; /*Energy read after OPT*/
double LUMO; /*Energy for specie II*/ //hard-coded
double MW;
int flag; /*flag = 0: ready to update; flag = -1: no need for update*/
int multi = 1;
int charge = 0;
void init(int natoms)
{ coords.resize(3*natoms);
anames.resize(natoms);
}
void get_xyz(ifstream &ostream)
{
if (!ostream)
{
cout << "Cannot read MM output file " << endl;
exit(-1);
}
string line;
vector<string> tok_line;
getline(ostream,line);
line = StringTools::newCleanString(line);
natoms = atoi(line.c_str());
getline(ostream,line);
anames.resize(natoms);
coords.resize(3*natoms);
for (int i=0; i<natoms; i++)
{
getline(ostream, line);
tok_line = StringTools::tokenize(line," ");
anames.at(i) = tok_line[0];
coords.at(3*i+0) = atof(tok_line[1].c_str());
coords.at(3*i+1) = atof(tok_line[2].c_str());
coords.at(3*i+2) = atof(tok_line[3].c_str());
}
return;
}
};
template<class T>
Node<T>::Node()
{
// default constructor
// this is to allow us to create an object without any initialization
}
// This constructor is just to set next pointer of a node and the data contained.
template<class T>
Node<T>::Node(const T& item,Node<T>* ptrnext)
{
this->data = item;
this->next = ptrnext;
}
template<class T>
Node<T>*Node<T>::NextNode()
{
return this->next;
}
// This methods inserts a node just after the node that the method belongs to
// TO-DO: Consider a better implementatio template<class T>
template<class T>
void Node<T>::InsertAfter(Node<T> *p)
{
p->next = this->next;
this->next = p;
}
// Deletes the node from the list and returns the deleted node
template<class T>
Node<T>* Node<T>::DeleteAfter()
{
Node<T>* tempNode = next;
if(next != NULL)
next = next->next;
return tempNode;
}
template<class T>
Node<T> * GetNode(const T& item, Node<T>* nextptr = NULL)
{
Node<T>* newnode; // Local ptr for new node
newnode = new Node<T>(item,nextptr);
if ( newnode == NULL)
{
cerr << "Memory allocation failed." << endl;
exit(1);
}
return newnode;
}
#endif // NODE_H