本文整理汇总了C++中Molecule::bondCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Molecule::bondCount方法的具体用法?C++ Molecule::bondCount怎么用?C++ Molecule::bondCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Molecule
的用法示例。
在下文中一共展示了Molecule::bondCount方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(MoleculeTest, removeAtom)
{
Molecule molecule;
Atom atom0 = molecule.addAtom(6);
Atom atom1 = molecule.addAtom(1);
Atom atom2 = molecule.addAtom(1);
Atom atom3 = molecule.addAtom(1);
Atom atom4 = molecule.addAtom(1);
molecule.addBond(atom0, atom1, 1);
molecule.addBond(atom0, atom2, 1);
molecule.addBond(atom0, atom3, 1);
molecule.addBond(atom0, atom4, 1);
EXPECT_EQ(5, molecule.atomCount());
EXPECT_EQ(4, molecule.bondCount());
molecule.removeAtom(atom0);
EXPECT_EQ(4, molecule.atomCount());
EXPECT_EQ(0, molecule.bondCount());
molecule.clearAtoms();
EXPECT_EQ(0, molecule.atomCount());
}
示例2: process
void BallAndStick::process(const Molecule &molecule,
Rendering::GroupNode &node)
{
// Add a sphere node to contain all of the spheres.
GeometryNode *geometry = new GeometryNode;
node.addChild(geometry);
SphereGeometry *spheres = new SphereGeometry;
spheres->identifier().molecule = &molecule;
spheres->identifier().type = Rendering::AtomType;
geometry->addDrawable(spheres);
for (Index i = 0; i < molecule.atomCount(); ++i) {
Core::Atom atom = molecule.atom(i);
unsigned char atomicNumber = atom.atomicNumber();
const unsigned char *c = Elements::color(atomicNumber);
Vector3ub color(c[0], c[1], c[2]);
spheres->addSphere(atom.position3d().cast<float>(), color,
static_cast<float>(Elements::radiusVDW(atomicNumber))
* 0.3f);
}
float bondRadius = 0.1f;
CylinderGeometry *cylinders = new CylinderGeometry;
cylinders->identifier().molecule = &molecule;
cylinders->identifier().type = Rendering::BondType;
geometry->addDrawable(cylinders);
for (Index i = 0; i < molecule.bondCount(); ++i) {
Core::Bond bond = molecule.bond(i);
Vector3f pos1 = bond.atom1().position3d().cast<float>();
Vector3f pos2 = bond.atom2().position3d().cast<float>();
Vector3ub color1(Elements::color(bond.atom1().atomicNumber()));
Vector3ub color2(Elements::color(bond.atom2().atomicNumber()));
Vector3f bondVector = pos2 - pos1;
float bondLength = bondVector.norm();
bondVector /= bondLength;
switch (bond.order()) {
case 3: {
Vector3f delta = bondVector.unitOrthogonal() * (2.0f * bondRadius);
cylinders->addCylinder(pos1 + delta, bondVector, bondLength, bondRadius,
color1, color2, i);
cylinders->addCylinder(pos1 - delta, bondVector, bondLength, bondRadius,
color1, color2, i);
}
default:
case 1:
cylinders->addCylinder(pos1, bondVector, bondLength, bondRadius,
color1, color2, i);
break;
case 2: {
Vector3f delta = bondVector.unitOrthogonal() * bondRadius;
cylinders->addCylinder(pos1 + delta, bondVector, bondLength, bondRadius,
color1, color2, i);
cylinders->addCylinder(pos1 - delta, bondVector, bondLength, bondRadius,
color1, color2, i);
}
}
}
}
示例3:
TEST(HydrogenToolsTest, adjustHydrogens_C2H4O)
{
Molecule mol;
Atom C1 = mol.addAtom(6);
Atom C2 = mol.addAtom(6);
Atom O1 = mol.addAtom(8);
mol.addBond(C1, C2, 1);
mol.addBond(C2, O1, 2);
HydrogenTools::adjustHydrogens(mol);
EXPECT_EQ(7, mol.atomCount());
EXPECT_EQ(6, mol.bondCount());
EXPECT_EQ(std::string("C2H4O"), mol.formula());
}
示例4:
TEST(CjsonTest, crystal)
{
CjsonFormat cjson;
Molecule molecule;
bool success = cjson.readFile(std::string(AVOGADRO_DATA) +
"/data/rutile.cjson", molecule);
EXPECT_TRUE(success);
EXPECT_EQ(cjson.error(), "");
EXPECT_EQ(molecule.data("name").toString(), "TiO2 rutile");
EXPECT_EQ(molecule.atomCount(), static_cast<size_t>(6));
EXPECT_EQ(molecule.bondCount(), static_cast<size_t>(0));
const UnitCell *unitCell = molecule.unitCell();
ASSERT_NE(unitCell, (UnitCell*)NULL);
EXPECT_TRUE(std::fabs((float)unitCell->a() - 2.95812f) < 1e-5f);
EXPECT_TRUE(std::fabs((float)unitCell->b() - 4.59373f) < 1e-5f);
EXPECT_TRUE(std::fabs((float)unitCell->c() - 4.59373f) < 1e-5f);
EXPECT_TRUE(std::fabs((float)unitCell->alpha() - (.5f * PI_F)) < 1e-5f);
EXPECT_TRUE(std::fabs((float)unitCell->beta() - (.5f * PI_F)) < 1e-5f);
EXPECT_TRUE(std::fabs((float)unitCell->gamma() - (.5f * PI_F)) < 1e-5f);
Atom atom = molecule.atom(5);
EXPECT_EQ(atom.atomicNumber(), 8);
EXPECT_TRUE(std::fabs((float)atom.position3d().x() - 1.479060f) < 1e-5f);
EXPECT_TRUE(std::fabs((float)atom.position3d().y() - 3.699331f) < 1e-5f);
EXPECT_TRUE(std::fabs((float)atom.position3d().z() - 0.894399f) < 1e-5f);
std::string cjsonStr;
cjson.writeString(cjsonStr, molecule);
Molecule otherMolecule;
cjson.readString(cjsonStr, otherMolecule);
const UnitCell *otherUnitCell = otherMolecule.unitCell();
ASSERT_NE(otherUnitCell, (UnitCell*)NULL);
EXPECT_FLOAT_EQ((float)otherUnitCell->a(), (float)unitCell->a());
EXPECT_FLOAT_EQ((float)otherUnitCell->b(), (float)unitCell->b());
EXPECT_FLOAT_EQ((float)otherUnitCell->c(), (float)unitCell->c());
EXPECT_FLOAT_EQ((float)otherUnitCell->alpha(), (float)unitCell->alpha());
EXPECT_FLOAT_EQ((float)otherUnitCell->beta(), (float)unitCell->beta());
EXPECT_FLOAT_EQ((float)otherUnitCell->gamma(), (float)unitCell->gamma());
Atom otherAtom = otherMolecule.atom(5);
EXPECT_EQ(otherAtom.atomicNumber(), atom.atomicNumber());
EXPECT_FLOAT_EQ((float)otherAtom.position3d().x(),
(float)atom.position3d().x());
EXPECT_FLOAT_EQ((float)otherAtom.position3d().y(),
(float)atom.position3d().y());
EXPECT_FLOAT_EQ((float)otherAtom.position3d().z(),
(float)atom.position3d().z());
}
示例5: rwmol
TEST(RWMoleculeTest, MoleculeToRWMolecule)
{
Molecule mol;
typedef Molecule::AtomType Atom;
typedef Molecule::BondType Bond;
Atom a0 = mol.addAtom(1);
Atom a1 = mol.addAtom(6);
Atom a2 = mol.addAtom(9);
Bond b0 = mol.addBond(a0, a2);
a1.setPosition3d(Vector3(0, 6, 9));
b0.setOrder(3);
RWMolecule rwmol(mol, 0);
EXPECT_EQ(rwmol.atomCount(), mol.atomCount());
EXPECT_EQ(rwmol.bondCount(), mol.bondCount());
EXPECT_EQ(rwmol.atom(2).atomicNumber(), mol.atom(2).atomicNumber());
EXPECT_EQ(rwmol.bond(0).order(), mol.bond(0).order());
}