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 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
16 {
17 lua_writestring("bond:\n Arguments:\n i [number]\n j [number]\n Bond i and j.\n");
18 return 0;
19 };
20 int args = lua_gettop(lua);
21 if (args != 2)
22 {
23 const std::string msg = "bond expects two atom indices as argument.\n";
24 lua_pushlstring(lua, msg.c_str(), msg.length());
25 return lua_error(lua);
26 }
27
29 li.read(lua, 1);
30 lj.read(lua, 2);
31
32 uint64_t i = li.n;
33 uint64_t j = lj.n;
34
35 if (i >= atomCount || j >= atomCount)
36 {
37 const std::string msg = "bond atom index larger than atom count.\n";
38 lua_pushlstring(lua, msg.c_str(), msg.length());
39 return lua_error(lua);
40 }
41
42 bonds[i].insert(j);
43 auto s = bonds[j];
44 if (s.find(i) != s.cend())
45 {
46 bonds[j].erase(i);
47 }
48 elementsUpdated = true;
49
50 return 0;
51}
52
63{
64 if (lua_gettop(lua) >= 1 && lua_isstring(lua, 1) && std::string(lua_tostring(lua, 1)) == "help")
65 {
66 lua_writestring("unbond:\n Arguments:\n i [number]\n j [number]\n Unbond i and j.\n");
67 return 0;
68 };
69 int args = lua_gettop(lua);
70 if (args != 2)
71 {
72 const std::string msg = "unbond expects two atom indices as argument.\n";
73 lua_pushlstring(lua, msg.c_str(), msg.length());
74 return lua_error(lua);
75 }
76
78 li.read(lua, 1);
79 lj.read(lua, 2);
80
81 uint64_t i = li.n;
82 uint64_t j = lj.n;
83
84 if (i >= atomCount || j >= atomCount)
85 {
86 const std::string msg = "unbond atom index larger than atom count.\n";
87 lua_pushlstring(lua, msg.c_str(), msg.length());
88 return lua_error(lua);
89 }
90
91 auto s = bonds[i];
92 if (s.find(j) != s.cend())
93 {
94 bonds[i].erase(j);
95 }
96
97 s = bonds[j];
98 if (s.find(i) != s.cend())
99 {
100 bonds[j].erase(i);
101 }
102 elementsUpdated = true;
103
104 return 0;
105}
106
107#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
bool elementsUpdated
Definition visualisationState.h:135
std::map< uint64_t, std::set< uint64_t > > bonds
Definition visualisationState.h:118
uint64_t atomCount
Definition visualisationState.h:128
int lua_unbond(lua_State *lua)
Lua binding to unbond 2 Atoms.
Definition bonds.h:62
int lua_bond(lua_State *lua)
Lua binding to bond 2 Atoms.
Definition bonds.h:13