void OptimizeLigandGeomety(Conformer& ligand, double chi_increment, std::vector<double> chi_stdev, std::string lp_atom, double unit_cell_length, double angle_tolerance, std::string output_dir) { if (ligand.parent()->conformer_states() == NULL) Log->error(FLERR, "There are no conformer states for the ligand!"); const std::vector<Linkage<std::string> >& chi_names = ligand.parent()->conformer_states()->degrees_of_freedom(); std::vector<double> chi_values = GetChiValues(ligand); //adjust chi to values between [0, 360] for (size_t i = 0; i < chi_values.size(); ++i) { chi_values[i] = (chi_values[i] < 0 ? chi_values[i] += 360 : chi_values[i]); } //loop through the possible chi angles, filling the ligand geometry map std::map<std::vector<double>, std::vector<double> > ligand_geometry; for(double chi1 = floor(chi_values[0] - chi_stdev[0]); chi1 < ceil(chi_values[0] + chi_stdev[0]); chi1 += chi_increment) { for(double chi2 = floor(chi_values[1] - chi_stdev[1]); chi2 < ceil(chi_values[1] + chi_stdev[1]); chi2 += chi_increment) { ligand.AdjustLinkage(chi_names[0], chi1); ligand.AdjustLinkage(chi_names[1], chi2); std::vector<double> chis; chis.push_back(chi1); chis.push_back(chi2); Vector3 v = CalculateLonePairDirection(ligand, lp_atom); //Calculate the dot product of v and z axis unit vector //cos(q) = v*w / (|v|*|w|) double angle_z = RADIANS_TO_DEGREES * acos(v.DotProduct(Vector3(0, 0, 1)) / v.Length()); //Calculate the dot product of v and the vector from the N to the metal (where the C4 symmetry axis is) Atom* N = ligand.Find(lp_atom); Vector3 N_metal(unit_cell_length - N->x(), - N->y(), 0); double angle_metal = RADIANS_TO_DEGREES * acos(v.DotProduct(N_metal) / (v.Length() * N_metal.Length())); if ((angle_z < (90.0 + angle_tolerance) && angle_z > (90.0 - angle_tolerance)) && (angle_metal < angle_tolerance)) { ligand_geometry[chis].push_back(angle_z); ligand_geometry[chis].push_back(angle_metal); //OutputStructure(ligand.parent()->parent()->parent()->parent()->parent()->parent(), chis, lp_atom, output_dir); Log->print("Optimized Cu binding PDB with chi1 " + Log->to_str(chi1) + ", chi2 " + Log->to_str(chi2)); OutputLatticeStructure(ligand.parent()->parent()->parent()->parent()->parent()->parent(), chis, unit_cell_length, lp_atom, output_dir); } } } OutputStat(ligand_geometry, lp_atom, output_dir); }