SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
bonds.h
Go to the documentation of this file.
1#ifndef BONDS_H
2#define BONDS_H
3
14{
15 int args = lua_gettop(lua);
16 if (args != 2)
17 {
18 const std::string msg = "bond expects two atom indices as argument.\n";
19 lua_pushlstring(lua, msg.c_str(), msg.length());
20 return lua_error(lua);
21 }
22
24 li.read(lua, 1);
25 lj.read(lua, 2);
26
27 uint64_t i = li.n;
28 uint64_t j = lj.n;
29
30 if (i >= atomCount || j >= atomCount)
31 {
32 const std::string msg = "bond atom index larger than atom count.\n";
33 lua_pushlstring(lua, msg.c_str(), msg.length());
34 return lua_error(lua);
35 }
36
37 bonds[i].insert(j);
38 auto s = bonds[j];
39 if (s.find(i) != s.cend())
40 {
41 bonds[j].erase(i);
42 }
43
44 return 0;
45}
46
57{
58 int args = lua_gettop(lua);
59 if (args != 2)
60 {
61 const std::string msg = "unbond expects two atom indices as argument.\n";
62 lua_pushlstring(lua, msg.c_str(), msg.length());
63 return lua_error(lua);
64 }
65
67 li.read(lua, 1);
68 lj.read(lua, 2);
69
70 uint64_t i = li.n;
71 uint64_t j = lj.n;
72
73 if (i >= atomCount || j >= atomCount)
74 {
75 const std::string msg = "unbond atom index larger than atom count.\n";
76 lua_pushlstring(lua, msg.c_str(), msg.length());
77 return lua_error(lua);
78 }
79
80 auto s = bonds[i];
81 if (s.find(j) != s.cend())
82 {
83 bonds[i].erase(j);
84 }
85
86 s = bonds[j];
87 if (s.find(i) != s.cend())
88 {
89 bonds[j].erase(i);
90 }
91
92 return 0;
93}
94
95#endif /* BONDS_H */
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
Interop for a number in Lua.
Definition LuaNumber.h:11
void read(lua_State *lua, int index)
Read the number from stack index index.
Definition LuaNumber.h:26
std::map< uint64_t, std::set< uint64_t > > bonds
Definition visualisationState.h:117
uint64_t atomCount
Definition visualisationState.h:127
int lua_unbond(lua_State *lua)
Lua binding to unbond 2 Atoms.
Definition bonds.h:56
int lua_bond(lua_State *lua)
Lua binding to bond 2 Atoms.
Definition bonds.h:13