summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/atom.rl
blob: 28bb7783f46edd9a5f7a9bfa5780e940dd52b258 (plain)
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

%%{
	
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
	
# NOTES:
#
#  1. Will need to 'include utilities "utilities.rl";' before including this file
#
#  2. Make declarations for the following variables visible in scope
#         int intVal, intVal2;
#         int x, y, z;
#         std::string stringVal, stringVal2;
#         int atomId, atomicNum;
#         char *lineStart;
#
#  3. Define the following functions
#         void newAtom(int atomId, int x, int y, int z, std::string const& atomStyle);
#         void newBond(std::string const& bondType, int targetAtomId);
#         void newBondDirection(int atomId1, int atomId2);
#         void newAtomInfo(std::string const& key, std::string const& value);
#         void syntaxError(std::string const& errorMessage);

	
	machine atom;
	
	atom_id =
		whole_number
		% { atomId = intVal; /*cerr << "atomId = " << atomId << endl;*/ }
	;
	
	atomic_num =
		'(' nonNEWLINEspace* whole_number nonNEWLINEspace* ')'
		% { atomicNum = intVal; /*cerr << "atomId = " << atomId << endl;*/}
	;
	
	xcoord = nonNEWLINEspace*  integer  nonNEWLINEspace*  %{x = intVal; };
	ycoord = nonNEWLINEspace*  integer  nonNEWLINEspace*  %{y = intVal; };
	zcoord = nonNEWLINEspace*  integer  nonNEWLINEspace*  %{z = intVal; };
	
	
	atom_coords =
		'(' xcoord ',' ycoord ',' zcoord  ')'
#% { cerr << "atom_coords = (" << x << ',' << y << ',' << z << ')' << endl; }
		;
	
	
	atom_style =
		char_string_with_space
		% { atomStyle = stringVal;
		    /*cerr << "atom_style = " << stringVal << endl;*/
		}
	;
	

	atom_decl_line =
		'atom'
		nonNEWLINEspace+
		atom_id
		nonNEWLINEspace+
		atomic_num
		nonNEWLINEspace+
		atom_coords
		(nonNEWLINEspace+ atom_style)?
		nonNEWLINEspace*
		EOL
		@ { newAtom(atomId, atomicNum, x, y, z, atomStyle); }
		;
	
	
	action newBondAction {
		newBond(stringVal, intVal);
	}
	
	bond_line =
		'bond'
		[123acg] @ { stringVal = *p; }
		(nonNEWLINEspace+
		 whole_number
		 % newBondAction
		)+
		nonNEWLINEspace*
		EOL
		;
	
	
	action newBondDirectionAction {
		newBondDirection(intVal, intVal2);
	}
	
	bond_direction_line =
		'bond_direction'
		nonNEWLINEspace+
		whole_number
		nonNEWLINEspace+
		whole_number2
		nonNEWLINEspace*
		EOL
		@ newBondDirectionAction
		;
	
	action newInfoAtomAction {
		// stripTrailingWhiteSpaces(stringVal);
		// stripTrailingWhiteSpaces(stringVal2);
		newAtomInfo(stringVal, stringVal2);
	}
	
	info_atom_line =
		'info'
		nonNEWLINEspace+
		'atom'
		nonNEWLINEspace+
		char_string_with_space
		nonNEWLINEspace*
		'='
		nonNEWLINEspace*
		char_string_with_space2
		nonNEWLINEspace*
		EOL
		@ newInfoAtomAction
		;
	
	atom_attrib_line =
		(bond_line  |  bond_direction_line  |  info_atom_line);
	
	
}%%