def __iter__(self): """Filter the constraints to be drawn. """ for aConstraint in self.constraints: if aConstraint.getRange(self.rangeCutOff) in self.range: if any(aResiNumber in self.residuesList for aResiNumber in aConstraint.ResiNumbers): if aConstraint.isValid(): if aConstraint.setValueFromStructure(): aConstraint.setViolationState(self.cutOff) if aConstraint.isSatisfied() in self.violationState: yield aConstraint else: errors.add_error_message("Distance issue with constraint :\n" + aConstraint.definition) else: errors.add_error_message("Selection issue with constraint :\n" + aConstraint.definition)
def checkID(atomSet): """ """ check = False newName = "" error_message = "" if str(atomSet.resi_number) in pdb: if atomSet.segid in (atom["segi"] for atom in pdb[str(atomSet.resi_number)]): if atomSet.atoms in (atom["name"] for atom in pdb[str(atomSet.resi_number)]): check = True else: if "*" not in atomSet.atoms: if atomSet.atoms == "HN": newName = "H" elif atomSet.atoms == "H": newName = "HN" elif lastDigit.search(atomSet.atoms): digit = lastDigit.search(atomSet.atoms).group()[0] newName = digit + lastDigit.sub("", atomSet.atoms) # put final digit at the beginning if newName in (atom["name"] for atom in pdb[str(atomSet.resi_number)]): check = True else: error_message = "Atom name not found" else: nameRoot = atomSet.atoms.replace("*", "") for aName in (atom["name"] for atom in pdb[str(atomSet.resi_number)]): if nameRoot in aName: check = True break if check is False: error_message = "Atom name not found" else: error_message = "Wrong segment / chain" else: error_message = "Residue number not found" if check is False: errors.add_error_message( "Can't find " + str(atomSet.atoms) + " in structure " + pdb["name"] + " because : " + error_message ) if newName: return {"valid": check, "NewData": {"atoms": newName}} else: return {"valid": check, "NewData": None}
def calcDistance(coord_init, coord_final): """ Calculate distance according to : ((sum of all distances^-6)/number of distances)^-1/6 or (sum of all distances^-6)^-1/6 """ result = None if len(coord_init) and len(coord_final): distance_list = (sqrt(sum((coord[0] - coord[1]) ** 2 for coord in zip(AtomA, AtomB))) for (AtomA, AtomB) in product(coord_init, coord_final)) try: sum6 = sum(pow(distance, -6) for distance in distance_list) if distance_method == 'ave6': result = pow(sum6/len(distance_list), -1./6) elif distance_method == 'sum6': result = pow(sum6, -1./6) except ValueError: errors.add_error_message("Problem using coordinates : " + str(coord_init) + " " + str(coord_final) + "\n" + " and distances list" + str(distance_list) + "\n") return result