Skip to content

Commit f334767

Browse files
committed
Zero-order edges produce incorrect assembly indices #64
1 parent 3164724 commit f334767

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎unitTests/graphioTester.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ int main()
194194
"extra type\n2\n1 2\nC C\n1 2\n",
195195
"expected 1 bond label, found 2"
196196
);
197+
expectRejected(
198+
"zero type\n2\n1 2\nC C\n0\n",
199+
"zero-order bonds are not supported"
200+
);
197201
expectRejected(
198202
"negative type\n2\n1 2\nC C\n-1\n",
199203
"bond label must be between 0 and"

‎unitTests/molfileParserTester.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ int main(int argc, char **argv)
153153
}
154154
assert(rejected);
155155

156+
string zeroOrderBond = validMolfile;
157+
const size_t zeroOrderPosition = zeroOrderBond.find(" 4 5 1");
158+
assert(zeroOrderPosition != string::npos);
159+
zeroOrderBond.replace(zeroOrderPosition, 9, " 4 5 0");
160+
molGraph zeroOrderDestination;
161+
string zeroOrderSentinel = "zero-order-sentinel";
162+
zeroOrderDestination.addAtom(zeroOrderSentinel);
163+
istringstream zeroOrderInput(zeroOrderBond);
164+
rejected = false;
165+
try
166+
{
167+
molfileParser(zeroOrderInput, zeroOrderDestination);
168+
}
169+
catch (const runtime_error &error)
170+
{
171+
rejected = string(error.what()).find(
172+
"zero-order bonds are not supported"
173+
) != string::npos;
174+
}
175+
assert(rejected);
176+
assert(zeroOrderDestination.mg.size() == 1);
177+
assert(zeroOrderDestination.mg.front().type == zeroOrderSentinel);
178+
assert(zeroOrderDestination.totalBonds == 0);
179+
156180
string negativeBondOrder = validMolfile;
157181
const size_t negativeBondPosition = negativeBondOrder.find(" 4 5 1");
158182
assert(negativeBondPosition != string::npos);

‎v5/graphio.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ inline void graphio(std::istream &ifs, molGraph &mg)
215215
std::to_string(std::numeric_limits<short>::max())
216216
);
217217
}
218+
if (value == 0)
219+
{
220+
throw std::runtime_error(
221+
"invalid native graph: zero-order bonds are not supported"
222+
);
223+
}
218224
bondLabels.push_back(static_cast<short>(value));
219225
}
220226

‎v5/molfileParser.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ void molfileParser(std::istream &molfile, molGraph &mg)
158158
throw std::runtime_error(
159159
"invalid molfile: bond order must be nonnegative"
160160
);
161+
if (bondOrder == 0)
162+
throw std::runtime_error(
163+
"invalid molfile: zero-order bonds are not supported"
164+
);
161165
parsed.addBond(atomA - 1, atomB - 1, bondOrder);
162166
}
163167
if (removeHydrogens)

0 commit comments

Comments
 (0)