/** Generates twinned/untwinned reflection IDs for easy searching. */ void Reflection::generateReflectionIds() { if (millerCount() == 0) { std::cout << "Warning! Miller count is 0" << std::endl; } int h = miller(0)->getH(); int k = miller(0)->getK(); int l = miller(0)->getL(); vec hkl = new_vector(h, k, l); for (int i = 0; i < ambiguityCount(); i++) { MatrixPtr ambiguityMat = matrixForAmbiguity(i); int asuH, asuK, asuL; ccp4spg_put_in_asu(spaceGroup, hkl.h, hkl.k, hkl.l, &asuH, &asuK, &asuL); vec hklAsu = new_vector(asuH, asuK, asuL); ambiguityMat->multiplyVector(&hklAsu); int newId = reflectionIdForMiller(hklAsu); reflectionIds.push_back(newId); } }
Reflection *Reflection::copy(bool copyMillers) { Reflection *newReflection = new Reflection(); newReflection->spgNum = spgNum; newReflection->activeAmbiguity = activeAmbiguity; newReflection->reflectionIds = reflectionIds; newReflection->refIntensity = refIntensity; newReflection->refSigma = refSigma; newReflection->refl_id = refl_id; newReflection->inv_refl_id = inv_refl_id; newReflection->resolution = resolution; for (int i = 0; i < millerCount(); i++) { MillerPtr newMiller; if (copyMillers) { newMiller = miller(i)->copy(); } else { newMiller = miller(i); } newReflection->addMiller(newMiller); } return newReflection; }
void weil(element_t w, element_t g, element_t h) { element_t gr; element_t hs; element_t r; element_t s; element_t z, z0, z1; element_init(z, Fq2); element_init(z0, Fq2); element_init(z1, Fq2); element_init_same_as(gr, g); element_init_same_as(hs, h); element_init_same_as(r, g); element_init_same_as(s, h); element_random(r); element_random(s); //point_random always takes the same square root //why not take the other one for once? element_neg(r, r); element_set_str(r, "[[40,0],[54,0]]", 0); element_set_str(s, "[[48,55],[28,51]]", 0); element_printf("chose R = %B\n", r); element_printf("chose S = %B\n", s); element_add(gr, g, r); element_add(hs, h, s); element_printf("P+R = %B\n", gr); element_printf("Q+S = %B\n", hs); miller(z, gr, r, g, hs); miller(z0, gr, r, g, s); element_div(z1, z, z0); element_printf("num: %B\n", z1); miller(z, hs, s, h, gr); miller(z0, hs, s, h, r); element_div(w, z, z0); element_printf("denom: %B\n", w); element_div(w, z1, w); element_clear(gr); element_clear(r); element_clear(hs); element_clear(s); element_clear(z); element_clear(z0); element_clear(z1); }
MillerPtr Reflection::acceptedMiller(int num) { int accepted = 0; for (int i = 0; i < millers.size(); i++) { if (miller(i)->accepted() && accepted == num) return miller(i); if (miller(i)->accepted()) accepted++; } return MillerPtr(); }
void Reflection::scale(double scale) { for (int i = 0; i < millerCount(); i++) { miller(i)->applyScaleFactor(scale); } }
void Reflection::resetFlip() { for (int j = 0; j < millerCount(); j++) { miller(j)->setFlipMatrix(MatrixPtr(new Matrix())); } }
void Reflection::setAdditionalWeight(double weight) { for (int i = 0; i < millerCount(); i++) { miller(i)->setAdditionalWeight(weight); } }
void Reflection::setFlip(int i) { for (int j = 0; j < millerCount(); j++) { MatrixPtr ambiguityMat = matrixForAmbiguity(i); miller(j)->setFlipMatrix(ambiguityMat); } }
bool Reflection::anyAccepted() { for (int i = 0; i < millers.size(); i++) { if (miller(i)->accepted()) return true; } return false; }
void Reflection::printDescription() { std::cout << "Mean intensity " << this->meanIntensity() << std::endl; std::cout << "Miller corrected intensities: "; for (int i = 0; i < millerCount(); i++) { std::cout << miller(i)->intensity() << ", "; } std::cout << std::endl; }
static void tate_9(element_ptr out, element_ptr P, element_ptr Q, element_ptr R) { element_t QR; element_init(QR, P->field); element_add(QR, Q, R); miller(out, P, QR, R, 9); element_square(out, out); element_clear(QR); }
static void tate_18(element_ptr out, element_ptr P, element_ptr Q, element_ptr R, element_ptr S) { mpz_t pow; element_t PR; element_t QS; element_init(PR, P->field); element_init(QS, P->field); element_t outd; element_init(outd, out->field); mpz_init(pow); mpz_set_ui(pow, (19*19-1)/18); element_add(PR, P, R); element_add(QS, Q, S); if (element_is0(QS)) { element_t S2; element_init(S2, P->field); element_double(S2, S); miller(out, PR, S, S2, 18); miller(outd, R, S, S2, 18); element_clear(S2); } else { miller(out, PR, QS, S, 18); miller(outd, R, QS, S, 18); } element_clear(PR); element_clear(QS); element_invert(outd, outd); element_mul(out, out, outd); element_pow_mpz(out, out, pow); element_clear(outd); mpz_clear(pow); }
int Reflection::rejectCount() { int count = 0; for (int i = 0; i < millerCount(); i++) { if (miller(i)->isRejected()) { count++; } } return count; }
int Reflection::acceptedCount() { int count = 0; for (int i = 0; i < millerCount(); i++) { if (miller(i)->accepted()) { count++; } } return count; }
void fasterweil2(element_t w, element_t g, element_t h) { element_t gr; element_t r; element_t z, z0, z1; element_init(z, Fq2); element_init(z0, Fq2); element_init(z1, Fq2); element_init_same_as(gr, g); element_init_same_as(r, g); element_random(r); //point_random always takes the same square root //why not take the other one for once? element_set_str(r, "[[48,55],[28,51]]", 0); element_printf("chose R = %B\n", r); element_add(gr, g, r); element_printf("P+R = %B\n", gr); miller(w, gr, r, g, h); element_printf("num: %B\n", w); millertate(z, h, gr); millertate(z0, h, r); element_div(z1, z, z0); element_printf("denom: %B\n", z1); element_div(w, w, z1); element_clear(z); element_clear(z0); element_clear(z1); element_clear(gr); element_clear(r); }
void fasterweil(element_t w, element_t g, element_t h) { element_t hs; element_t s; element_t z, z0, z1; element_init(z, Fq2); element_init(z0, Fq2); element_init(z1, Fq2); element_init_same_as(hs, h); element_init_same_as(s, h); element_random(s); //point_random always takes the same square root //why not take the other one for once? element_set_str(s, "[[48,55],[28,51]]", 0); element_printf("chose S = %B\n", s); element_add(hs, h, s); element_printf("Q+S = %B\n", hs); millertate(z, g, hs); millertate(z0, g, s); element_div(z1, z, z0); element_printf("num: %B\n", z1); miller(w, hs, s, h, g); element_printf("denom: %B\n", w); element_div(w, z1, w); element_clear(z); element_clear(z0); element_clear(z1); element_clear(hs); element_clear(s); }
static void tate_3(element_ptr out, element_ptr P, element_ptr Q, element_ptr R) { mpz_t six; mpz_init(six); mpz_set_ui(six, 6); element_t QR; element_t e0; element_init(QR, P->field); element_init(e0, out->field); element_add(QR, Q, R); //for subgroup size 3, -2P = P, hence //the tangent line at P has divisor 3(P) - 3(O) miller(out, P, QR, R, 3); element_pow_mpz(out, out, six); element_clear(QR); element_clear(e0); mpz_clear(six); }
void Reflection::calculateResolution(MtzManager *mtz) { int h = millers[0]->getH(); int k = millers[0]->getK(); int l = millers[0]->getL(); // calculate resolution vec aStar, bStar, cStar; reciprocalAxes(&aStar, &bStar, &cStar); double dotAA = dot_product_for_vectors(aStar, aStar); double dotBB = dot_product_for_vectors(bStar, bStar); double dotCC = dot_product_for_vectors(cStar, cStar); double dotAB = dot_product_for_vectors(aStar, bStar); double dotAC = dot_product_for_vectors(aStar, cStar); double dotBC = dot_product_for_vectors(bStar, cStar); double term1 = h * h * dotAA; double term2 = k * k * dotBB; double term3 = l * l * dotCC; double term4 = 2 * h * k * dotAB; double term5 = 2 * h * l * dotAC; double term6 = 2 * k * l * dotBC; double dStarSqr = term1 + term2 + term3 + term4 + term5 + term6; this->resolution = sqrt(dStarSqr); for (int i = 0; i < millerCount(); i++) { miller(i)->setResolution(resolution); } // std::cout << h << " " << k << " " << l << " " << resolution << std::endl; }
/** Takes the h,k,l values, flips the Miller and folds back onto the asymmetric unit. If the Miller indices are the same, it is twinned. (Not suitable for non-hemihedral twinning at the moment) */ bool Reflection::isTwinned() { if (millerCount() > 0) { int h, k, l = 0; int trueH = miller(0)->getH(); int trueK = miller(0)->getK(); int trueL = miller(0)->getL(); miller(0)->flip(); MillerPtr firstMiller = miller(0); ccp4spg_put_in_asu(spaceGroup, firstMiller->getH(), firstMiller->getK(), firstMiller->getL(), &h, &k, &l); miller(0)->flip(); return (h == trueH && k == trueK && l == trueL); } else { return false; } }