def test_constructors(self): qlist = [] for i in range(10): atom = self.molecule.addAtom() self.list.append(atom) qlist.append(atom) self.assertEqual(self.list.size, 10) list2 = Avogadro.PrimitiveList(self.list) self.assertEqual(list2.size, 10) list3 = Avogadro.PrimitiveList(qlist) self.assertEqual(list3.size, 10)
def selectBackbone(self, glwidget): mol = glwidget.molecule # create a PrimitiveList to call GLWidget.setSelected(PrimitiveList, bool) primitiveList = Avogadro.PrimitiveList() # find the backbone atoms for atom in mol.atoms: # get the atomId and strip of white spaces atomId = atom.residue.atomId(atom.id).strip() print atomId # add the atom to the list if the atomId matches N, CA, C, O or H if atomId == "N": primitiveList.append(atom) elif atomId == "CA": primitiveList.append(atom) elif atomId == "C": primitiveList.append(atom) elif atomId == "O": primitiveList.append(atom) elif atomId == "H": primitiveList.append(atom) # find all bonds between backbone atoms for bond in mol.bonds: beginAtom = bond.beginAtom endAtom = bond.endAtom if primitiveList.contains(beginAtom) and primitiveList.contains( endAtom): primitiveList.append(bond) # clear the current selection glwidget.clearSelected() # select the backbone atom glwidget.setSelected(primitiveList, True)
def test_primitives(self): molecule = Avogadro.molecules.addMolecule() for i in range(10): molecule.addAtom() list = Avogadro.PrimitiveList(molecule.atoms) for engine in self.engines: self.assertEqual(engine.primitives.size, 0) engine.primitives = list self.assertNotEqual(engine.primitives.size, 0) engine.clearPrimitives() self.assertEqual(engine.primitives.size, 0)
def selectBindingSite(self, glwidget): # returns (double, bool ok) as tuple result = QInputDialog.getDouble( None, "Create Binding Site Around Selection", "radius", 5.0, 2.0, 20.0, 1) if not result[1]: return r = result[0] r2 = r * r selectedAtoms = glwidget.selectedPrimitives.subList( Avogadro.PrimitiveType.AtomType) newSelection = Avogadro.PrimitiveList() atomIds = [] for residue in glwidget.molecule.residues: keepResidue = False # compute distance between residue atoms and selected atoms for atomId in residue.atoms: atom = glwidget.molecule.atomById(atomId) if not atom: continue for selectedAtom in selectedAtoms: ab = selectedAtom.pos - atom.pos dist2 = dot(ab, ab) if dist2 < r2: keepResidue = True break if keepResidue: break if keepResidue: for atomId in residue.atoms: atom = glwidget.molecule.atomById(atomId) newSelection.append(atom) atomIds.append(atom.id) # find all bonds between the atoms for bond in glwidget.molecule.bonds: beginAtom = bond.beginAtom endAtom = bond.endAtom if atomIds.count(beginAtom.id) and atomIds.count(endAtom.id): newSelection.append(bond) glwidget.setSelected(newSelection, True)
def test_namedSelections(self): l = Avogadro.PrimitiveList([self.molecule.atom(0)]) self.glwidget.addNamedSelection("test", l) self.assertNotEqual(len(self.glwidget.namedSelections), 0) self.assertEqual(self.glwidget.namedSelections[0], "test") self.glwidget.removeNamedSelection("test") self.assertEqual(len(self.glwidget.namedSelections), 0) self.glwidget.addNamedSelection("test", l) self.glwidget.removeNamedSelection(0) self.assertEqual(len(self.glwidget.namedSelections), 0) self.glwidget.addNamedSelection("test", l) self.glwidget.renameNamedSelection(0, "test2") self.assertEqual(self.glwidget.namedSelections[0], "test2") self.assertNotEqual(self.glwidget.namedSelectionPrimitives("test2"), None) self.assertNotEqual(self.glwidget.namedSelectionPrimitives(0), None)
def setUp(self): self.molecule = Avogadro.molecules.addMolecule() self.list = Avogadro.PrimitiveList()