MCPcopy Create free account
hub / github.com/Kitware/VTK / MoleculeExampleCode1

Function MoleculeExampleCode1

Domains/Chemistry/Testing/Cxx/TestMolecule.cxx:12–56  ·  view source on GitHub ↗

Example code from the molecule documentation. If this breaks, update the docs in vtkMolecule.h

Source from the content-addressed store, hash-verified

10// Example code from the molecule documentation. If this breaks,
11// update the docs in vtkMolecule.h
12bool MoleculeExampleCode1()
13{
14 vtkNew<vtkMolecule> mol;
15 vtkAtom h1 = mol->AppendAtom(1, 0.0, 0.0, -0.5);
16 vtkAtom h2 = mol->AppendAtom(1, 0.0, 0.0, 0.5);
17 vtkBond b = mol->AppendBond(h1, h2, 1);
18 int errors(0);
19
20 if (fabs(b.GetLength() - 1.0) > 1e-8)
21 {
22 std::cout << "Error bond length incorrect. Expected 1.0, but got " << b.GetLength()
23 << std::endl;
24 ++errors;
25 }
26
27 if (!h1.GetPosition().Compare(vtkVector3f(0.0, 0.0, -0.5), 1e-8))
28 {
29 std::cout << "Error atom position incorrect. Expected 0.0, 0.0, -0.5 but got "
30 << h1.GetPosition() << std::endl;
31 ++errors;
32 }
33
34 if (!h2.GetPosition().Compare(vtkVector3f(0.0, 0.0, 0.5), 1e-8))
35 {
36 std::cout << "Error atom position incorrect. Expected 0.0, 0.0, 0.5 but got "
37 << h2.GetPosition() << std::endl;
38 ++errors;
39 }
40
41 if (h1.GetAtomicNumber() != 1)
42 {
43 std::cout << "Error atomic number incorrect. Expected 1 but got " << h1.GetAtomicNumber()
44 << std::endl;
45 ++errors;
46 }
47
48 if (h2.GetAtomicNumber() != 1)
49 {
50 std::cout << "Error atomic number incorrect. Expected 1 but got " << h2.GetAtomicNumber()
51 << std::endl;
52 ++errors;
53 }
54
55 return errors == 0;
56}
57
58// Example code from the molecule documentation. If this breaks,
59// update the docs in vtkMolecule.h

Callers 1

TestMoleculeFunction · 0.85

Calls 7

AppendAtomMethod · 0.80
AppendBondMethod · 0.80
vtkVector3fClass · 0.50
GetLengthMethod · 0.45
CompareMethod · 0.45
GetPositionMethod · 0.45
GetAtomicNumberMethod · 0.45

Tested by

no test coverage detected