Example #1
0
	void calculateResidueChi2Angles
		(const Chain& fragment, HashMap<const Residue*,float>& residue_angles)
	{
		float angle = 0; //FLOAT_VALUE_NA;
		
		// extract all residues: iterate over all composites and
		// check whether they are Residues
		ResidueConstIterator	it = fragment.beginResidue();
		for (; +it; ++it)
		{
			angle =  calculateResidueChi2Angles(*it);
			residue_angles.insert(std::pair<const Residue*, float>(&*it, angle));
		}
	}
Example #2
0
	// setup the internal datastructures for the component
	bool CharmmTorsion::setup()
		throw(Exception::TooManyErrors)
	{
		if (getForceField() == 0) 
		{
			Log.error() << "CharmmTorsion::setup: component not bound to force field" << endl;
			return false;
		}

		// clear torsion array
		torsion_.clear();

 		Options& options = getForceField()->options;
		if (options.has(CHARMM_TORSIONS_ENABLED))
		{
			if (!options.getBool(CHARMM_TORSIONS_ENABLED))
			{
				setEnabled(false);
				return true;
			}
			else
			{
				setEnabled(true);
			}
		}


		// extract the torsion parameters from the parameter file
		bool result;
		CharmmFF* charmm_force_field = dynamic_cast<CharmmFF*>(force_field_);
		bool has_initialized_parameters = true;
		if ((charmm_force_field == 0) || !charmm_force_field->hasInitializedParameters())
		{
			has_initialized_parameters = false;
		}

		if (!has_initialized_parameters)
		{
			// extract the torsion parameters
			result = torsion_parameters_.extractSection(getForceField()->getParameters(), "Torsions");

			if (result == false) 
			{
				Log.error() << "cannot find section Torsions" << endl;
				return false;
			}

			// check whether the torsions are contructed from the connectivity or whether
			// we read them from the ResidueTorsions section in the parameter file
			if (getForceField()->getParameters().getParameterFile().hasSection("ResidueTorsions"))
			{
				result = residue_torsions_.extractSection(getForceField()->getParameters(), "ResidueTorsions");
				if (result == false)
				{
					Log.error() << "CharmmTorsion::setup: cannot parse section Torsions" << endl;
					return false;
				}
				
				use_residue_torsion_list_ = true;
			}
		}


		// calculate the torsions
		vector<Atom*>::const_iterator atom_it = getForceField()->getAtoms().begin();
		Atom::BondIterator it1;
		Atom::BondIterator it2;
		Atom::BondIterator it3;

		Atom*	a1;
		Atom*	a2;
		Atom*	a3;
		Atom*	a4;

		// proper torsion will be added to the torsion vector
		for (; atom_it != getForceField()->getAtoms().end(); ++atom_it) 
		{
			for (it1 = (*atom_it)->beginBond(); +it1 ; ++ it1) 
			{
				if (it1->getType() == Bond::TYPE__HYDROGEN) continue; // Skip H-bonds!
				if (*atom_it == it1->getFirstAtom()) 
				{
					// central atoms
					a2 = *atom_it;
					a3 = const_cast<Atom*>(it1->getSecondAtom());

					for (it2 = (*atom_it)->beginBond(); +it2 ; ++it2) 
					{
						if (it2->getType() == Bond::TYPE__HYDROGEN) continue; // Skip H-bonds!
						if ((*it2).getSecondAtom() != (*it1).getSecondAtom()) 
						{
							// determine the first atom
							if ((*it2).getFirstAtom() == *atom_it) 
							{
								a1 = const_cast<Atom*>(it2->getSecondAtom());
							} 
							else 
							{
								a1 = const_cast<Atom*>(it2->getFirstAtom());
							}

							for (it3 = const_cast<Atom*>(it1->getSecondAtom())->beginBond(); +it3 ; ++it3) 
							{
								if (it3->getType() == Bond::TYPE__HYDROGEN) continue; // Skip H-bonds!
								if ((*it3).getFirstAtom() != a2 ) 
								{
									// determine the fourth atom a4
									if ((*it3).getFirstAtom() == a3)
									{
										a4 = const_cast<Atom*>(it3->getSecondAtom());
									} 
									else 
									{
										a4 = const_cast<Atom*>(it3->getFirstAtom());
									}

									if (getForceField()->getUseSelection() == false ||
											(getForceField()->getUseSelection() == true &&
											 (a1->isSelected() && a2->isSelected() && a3->isSelected() && a4->isSelected())))
									{
										// if we use ResidueTorsions (i.e. a list of torsions for each
										// residue is specified in the parameter file), we have to check
										// if to consider this torsion
										if (use_residue_torsion_list_)
										{
											String atom_name_A = a1->getName();
											String atom_name_B = a2->getName();
											String atom_name_C = a3->getName();
											String atom_name_D = a4->getName();
											
											// the second atom is always in the residue in question
											// 											
											// now check for the other three atoms: if it is in a different residue,
											// add a "+" or "-"
											Residue* res = a2->getAncestor(RTTI::getDefault<Residue>());
											Chain* chain = a2->getAncestor(RTTI::getDefault<Chain>());
											if (res != 0 && chain != 0)
											{
												// check whether a1, a3, and a4 are in the same residue
												// or in the previous (marked as -) or the next residue (marked as +)
												ResidueIterator res_it;
												if (a1->getAncestor(RTTI::getDefault<Chain>()) == chain)
												{
													Residue* last_res = 0;
													for (res_it = chain->beginResidue(); +res_it; last_res = &*res_it, ++res_it)
													{
														if (&*res_it == res)
														{
															if (a1->getAncestor(RTTI::getDefault<Residue>()) == last_res)
															{
																atom_name_A = "-" + atom_name_A;
															}
															if (a3->getAncestor(RTTI::getDefault<Residue>()) == last_res)
															{
																atom_name_C = "-" + atom_name_C;
															}
															if (a4->getAncestor(RTTI::getDefault<Residue>()) == last_res)
															{
																atom_name_D = "-" + atom_name_D;
															}
														}
														if (last_res == res)
														{
															if (a1->getAncestor(RTTI::getDefault<Residue>()) == &*res_it)
															{
																atom_name_A = "+" + atom_name_A;
															}
															if (a3->getAncestor(RTTI::getDefault<Residue>()) == &*res_it)
															{
																atom_name_C = "+" + atom_name_C;
															}
															if (a4->getAncestor(RTTI::getDefault<Residue>()) == &*res_it)
															{
																atom_name_D = "+" + atom_name_D;
															}
														}
													}
												}
											}

											// if we are in a CYS-S residue, all atoms that are in another CYS-S
											// are prefixed by "="
											if ((res != 0) && res->hasProperty(Residue::PROPERTY__HAS_SSBOND))
											{	
												Residue* other_res = a1->getAncestor(RTTI::getDefault<Residue>());
												if ((other_res != 0) && (other_res != res) 
														&& other_res->hasProperty(Residue::PROPERTY__HAS_SSBOND))
												{
													atom_name_A = "=" + atom_name_A;
												}
												other_res = a3->getAncestor(RTTI::getDefault<Residue>());
												if ((other_res != 0) && (other_res != res)
														&& other_res->hasProperty(Residue::PROPERTY__HAS_SSBOND))
												{
													atom_name_C = "=" + atom_name_C;
												}
												other_res = a4->getAncestor(RTTI::getDefault<Residue>());
												if ((other_res != 0) && (other_res != res)
														&& other_res->hasProperty(Residue::PROPERTY__HAS_SSBOND))
												{
													atom_name_D = "=" + atom_name_D;
												}
											}
													
											// check whether the names are known in ResidueTorsions
											if (res != 0)
											{
												if (!residue_torsions_.hasTorsion(res->getFullName(), atom_name_A, atom_name_B, atom_name_C, atom_name_D))
												{
													continue;
												}
											} 
											else 
											{
												Log.warn() << "Cannot identify torsion for (UNKNOWN)" << " " << atom_name_A 
													<< "/" << atom_name_B << "/" << atom_name_C << "/" << atom_name_D << endl;

												continue;
											}
										}
										
										// search torsion parameters for (a1,a2,a3,a4)
										Atom::Type type_a1 = a1->getType();
										Atom::Type type_a2 = a2->getType();
										Atom::Type type_a3 = a3->getType();
										Atom::Type type_a4 = a4->getType();
										CosineTorsion::Values values;
										CosineTorsion::SingleData tmp;
										tmp.atom1 = a1;
										tmp.atom2 = a2;
										tmp.atom3 = a3;
										tmp.atom4 = a4;

										// retrieve parameters for the torsion
										bool found = false;
										if (torsion_parameters_.assignParameters(values, type_a1, type_a2, type_a3, type_a4)) 
										{
											found = true;
										} 
										else if (torsion_parameters_.assignParameters(values, Atom::ANY_TYPE, type_a2, type_a3, Atom::ANY_TYPE)) 
										{
											found = true;
										}

										// complain about mising parameters or store this torsion
										// in the torsion_ array
										if (found) 
										{
											for (unsigned char j = 0; j < values.n; j++) 
											{
												tmp.values = values.values[j];
												torsion_.push_back(tmp);
											}
										} 
										else 
										{
											getForceField()->error() << "CharmmTorsion::setup: cannot find torsion parameters for:"
												<< force_field_->getParameters().getAtomTypes().getTypeName(type_a1) << "-"
												<< force_field_->getParameters().getAtomTypes().getTypeName(type_a2) << "-"
												<< force_field_->getParameters().getAtomTypes().getTypeName(type_a3) << "-"
												<< force_field_->getParameters().getAtomTypes().getTypeName(type_a4) << endl;

												getForceField()->getUnassignedAtoms().insert(a1);
												getForceField()->getUnassignedAtoms().insert(a2);
												getForceField()->getUnassignedAtoms().insert(a3);
												getForceField()->getUnassignedAtoms().insert(a4);
										}
									}
								} 
							}
						}
					}
				}
			}
		}

		return true;
	}
Example #3
0
	/**********************************************
	 *   determine the new Secondary Structure and
	 *   replace the old one with the new one
	 **********************************************/
	Processor::Result SecondaryStructureProcessor::operator() (Composite &composite)
	{
		if (!RTTI::isKindOf<Chain>(composite))
		{
			return Processor::CONTINUE;
		}

		Chain* p = RTTI::castTo<Chain>(composite);
		HBondProcessor hbp;

		p->apply(hbp);       // find all posible HBonds
		
		HBonds_ = hbp.getBackboneHBondPattern();
		ResidueIterator ri = p->beginResidue();
		 
		if (!(+ri))
		{
			return Processor::CONTINUE;
		}
		
		// locate the Secondary Structures
		compute_();

		//----------associate new Secondary Structures (SS) for each residue -----
	  // - summarize equal residues in one new SS (new_ss)
		// - push for each residue the new SS into new_parent  
		// - push all residues into residues
		
		SecondaryStructure* ss = 0;
		char     last_struct   = 'X';
		Position resnum        = 0;
 
		vector<SecondaryStructure*> new_ss;
		vector<SecondaryStructure*> new_parent;
		vector<Residue*> 						residues;

		if (summary_.size() == 0)
			return Processor::CONTINUE;
		
		for (; +ri; ++ri)
		{
			if (resnum >= summary_.size())
			{
				Log.error() << "A problem occured in " << __FILE__ << " " << __LINE__ << std::endl;
				return Processor::CONTINUE;
			}

			// depending on the last type of secondary structure we have seen,
			// we need to react differently to merge them sensibly
			if (last_struct != summary_[resnum])
			{
				switch (last_struct)
				{
					case 'L': // we are in a loop
						// note that we identify 'real' loops, isolated bridges and turns (-,B,T)
						// and map them all to loops. Thus we need to determine here if the current
						// residue also maps to a loop (we already know that the last residue was one)
						switch (summary_[resnum])
						{
							case '-':
							case 'B':
							case 'T': break; // nothing to see here... please walk on...

							default:
								// the current residue is no loop => build a new SecondaryStructure
								ss = new SecondaryStructure;
								last_struct = setSecondaryStructureType_(ss, summary_[resnum]);
								new_ss.push_back(ss);
						}
						break;
				
					default: // in all other cases, setSecondaryStructure does the hard work
						ss = new SecondaryStructure;
						last_struct = setSecondaryStructureType_(ss, summary_[resnum]);
						new_ss.push_back(ss);
				}
			}

			// in all cases, ss is now the new parent of this residue
			new_parent.push_back(ss);
			residues.push_back(&*ri);
			
			resnum++;
		}
		
		// ------ insert Residues to new SS ---------------
		for (Position i = 0; i < residues.size(); i++)
		{
			new_parent[i]->insert(*residues[i]);
		}
	
		// ------ remove old SecondaryStructures ----------
		// we have to be sure not to delete a SS which has an SS as parent!
		// because it would be deleted twice
		vector<SecondaryStructure*> to_remove;
		SecondaryStructureIterator ssit = p->beginSecondaryStructure();
		for (; +ssit; ++ssit)
		{
			if ((*ssit).getParent() == 0 ||
					!RTTI::isKindOf<SecondaryStructure>(*(*ssit).getParent()))
			{
				to_remove.push_back(&*ssit);
			}
		}


		for (Position i = 0; i < to_remove.size(); i++)
		{
			delete to_remove[i];
		}

		BALL_POSTCONDITION_EXCEPTION(p->countSecondaryStructures() == 0, 
		 "SecondaryStructureProcessor did not remove all old secondary structures!")
		
		// ------ insert new SecondaryStructures ----------
		for (Position i = 0; i < new_ss.size(); i++)
		{
			p->insert(*new_ss[i]);
		}
	
		BALL_POSTCONDITION_EXCEPTION(p->countSecondaryStructures() == new_ss.size(),
		 "SecondaryStructureProcessor did not add all new secondary structures!")

		return Processor::CONTINUE;
	}