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

Method MakeBonds

IO/Chemistry/vtkMoleculeReaderBase.cxx:276–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276unsigned int vtkMoleculeReaderBase::MakeBonds(
277 vtkPoints* points, vtkIdTypeArray* atomTypes, vtkCellArray* newBonds)
278{
279 double X[3], Y[3];
280
281 vtkSmartPointer<vtkPolyData> dataset = vtkSmartPointer<vtkPolyData>::New();
282 dataset->SetPoints(points);
283
284 vtkSmartPointer<vtkIdList> neighborAtoms = vtkSmartPointer<vtkIdList>::New();
285
286 // Add atoms to the molecule first because an atom must
287 // must be declared before bonds involving it.
288 if (this->Molecule)
289 {
290 for (vtkIdType i = 0; i < this->NumberOfAtoms; ++i)
291 {
292 points->GetPoint(i, X);
293 this->Molecule->AppendAtom(atomTypes->GetValue(i), X[0], X[1], X[2]);
294 }
295 }
296
297 double max, dist, radius;
298 vtkIdType bond[2];
299 unsigned int numberOfBonds = 0;
300
301 vtkSmartPointer<vtkPointLocator> locator = vtkSmartPointer<vtkPointLocator>::New();
302 locator->SetDataSet(dataset);
303
304 for (vtkIdType atomId = this->NumberOfAtoms - 1; atomId > 0; --atomId)
305 {
306 bond[0] = atomId;
307 points->GetPoint(atomId, X);
308
309 vtkIdType atom1Type = atomTypes->GetValue(atomId);
310
311 /* Find all the atoms in the neighborhood at the max acceptable
312 * bond distance
313 */
314 radius =
315 (this->PeriodicTable->GetCovalentRadius(atom1Type) + 2.0 + 0.56) * std::max(BScale, HBScale);
316 locator->FindPointsWithinRadius(radius, X, neighborAtoms);
317
318 for (vtkIdType k = neighborAtoms->GetNumberOfIds() - 1; k >= 0; --k)
319 {
320 vtkIdType neighborAtomId = neighborAtoms->GetId(k);
321 vtkIdType atom2Type = atomTypes->GetValue(neighborAtomId);
322
323 // Skip points with which a bond may have already been created
324 if (neighborAtomId >= atomId)
325 {
326 continue;
327 }
328
329 /*
330 * The outer loop index 'atomId' is AFTER the inner loop 'neighborAtomId': 'atomId'
331 * leads 'neighborAtomId' in the list: since hydrogens traditionally follow
332 * the heavy atom they're bonded to, this makes it easy to quit
333 * bonding to hydrogens after one bond is made by breaking out of

Callers 1

ReadMoleculeMethod · 0.95

Calls 15

AppendAtomMethod · 0.80
GetCovalentRadiusMethod · 0.80
AppendBondMethod · 0.80
NewFunction · 0.50
maxFunction · 0.50
SetPointsMethod · 0.45
GetPointMethod · 0.45
GetValueMethod · 0.45
SetDataSetMethod · 0.45
GetNumberOfIdsMethod · 0.45
GetIdMethod · 0.45

Tested by

no test coverage detected