Ejemplo n.º 1
0
std::pair<PeakSet, size_t> EnvelopFinder::extendPeakSet(RichList& island, RichPeakListByMZ::iterator iter_mz, unsigned int charge)
	{
		
		// Candidate base peak. Notice that this might not be the monoisotopic peak for molecules with high mass values.
		RichPeakPtr expr_base_pk = *iter_mz;
		int mode = param.getParameter<int>("mode").first;
		double mass = calculateMass(expr_base_pk->mz, charge * mode);
		EnvelopBoundary bound = this->createBoundary(mass, charge);

		// The reason of creating an object called envelop is because during the extension of peakset towards different directions, there might be multiple matching for given shift. 
		PeakSet pk_set(bound);

		InfoPeakPtr pk_infor = boost::make_shared<InfoPeak>(expr_base_pk->resolution, 0.0, 0.5, 0.0);
		
		pk_set.addPeak(0, expr_base_pk, pk_infor);

		RichPeakListByMZ& pks_mz = island.getPeakListByType<peak_mz>();

		// Shift towards right along the mz axis.
		size_t max_env = this->extendPeak(pk_set, pks_mz, iter_mz, charge, 1);
		// TBD: Shift towards left along the mz axis.
		//this->extendPeak(pk_set, pks_mz, iter_mz, charge, -1);

		return std::make_pair(pk_set,max_env);
	}
Ejemplo n.º 2
0
Ball::Ball(double x, double y, double radius, double speedX, double speedY, sf::Color color, bool isActive) {
	
	btCollisionShape* shape = new btSphereShape(radius);
	btDefaultMotionState* mState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(x, y, 0)));
	double mass;
	if(isActive) {
		mass = calculateMass(radius);
	} else {
		mass = 0;
	}
	btVector3 inertia(0, 0, 0);
	shape->calculateLocalInertia(mass, inertia);
	btRigidBody::btRigidBodyConstructionInfo ci(mass, mState, shape, inertia);
	rigidBody = new btRigidBody(ci);
	rigidBody->setActivationState(DISABLE_DEACTIVATION);
	rigidBody->setRestitution(defaultRestitution);
	rigidBody->setDamping(0, 0);
	rigidBody->setFriction(defaultFriction);

	setVelX(speedX);
	setVelY(speedY);

	this->radius = radius;
	this->color = color;
	this->isActive = isActive;
	objectType = OBJECT_TYPE_BALL;

}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
void PD_LPS::initialize(double E, double nu, double delta, int dim, double h)
{
    Force::initialize(E, nu, delta, dim, h);
    m_delta = delta;
    m_dim = dim;
    m_mu = 0.5*E/(1 + nu);
    m_nu = nu;

    if(dim == 3)
    {
        m_k = E/(3.*(1. - 2.*nu));
    }
    else if(dim == 2)
    {
        m_k  = E/(2.*(1. - nu));
    }
    else if(dim == 1)
    {
        m_k = E;
    }
    else
    {
        cerr << "ERROR: dimension " << dim << " not supported." << endl;
        cerr << "use 1, 2 or 3." << endl;
        exit(EXIT_FAILURE);
    }
    calculateMass();
}
Ejemplo n.º 4
0
TetrahedronSystem::TetrahedronSystem(ATetrahedronMesh * md)
{
	m_hostTetrahedronVicinityInd = new BaseBuffer;
	m_hostTetrahedronVicinityStart = new BaseBuffer;
	m_hostElementValue = new BaseBuffer;
	create(md->numTetrahedrons() + 100, md->numTetrahedrons() * 4 + 400, md->numPoints() + 400);
	m_hostElementValue->create((md->numTetrahedrons() + 100) * 4);
    
    Vector3F * p = md->points();
	unsigned i;
	for(i=0; i< md->numPoints(); i++)
	    addPoint((float *)&p[i]);
	
	unsigned * ind = (unsigned *)md->indices();
	for(i=0; i< md->numTetrahedrons(); i++)
		addTetrahedron(ind[i*4], ind[i*4+1], ind[i*4+2], ind[i*4+3]);
		
	unsigned * anchor = md->anchors();
	for(i=0; i< md->numPoints(); i++) {
        //std::cout<<"a "<<anchor[i];
		if(anchor[i] > 0) hostAnchor()[i] = anchor[i];
	}
// density of nylon = 1.15 g/cm^3
// very low density is unstable
    std::cout<<"\n initial volume "<<md->volume()
       <<"\n initial mass "<<(100.f * md->volume())
       <<"\n";
    setTotalMass(100.f * md->volume());
    setInitialTotalMass(100.f * md->volume());
    calculateMass();
    createL2Vicinity();
}
Ejemplo n.º 5
0
void molecule_t::addElement(element *e, int count)
{
    m_composition.insert(e,count);
    m_mass = calculateMass(m_composition);
    m_abundance = calculateAbundance(m_composition);
}
Ejemplo n.º 6
0
molecule_t::molecule_t(composition_t composition)
{
    m_composition = composition;
    m_mass = calculateMass(composition);
}
Ejemplo n.º 7
0
	size_t EnvelopFinder::extendPeak(PeakSet& pk_set, RichPeakListByMZ& pks_mz,RichPeakListByMZ::iterator iter_mz, unsigned int charge, int direction)
	{
		//int dist = direction > 0 ? std::distance(iter_mz, pks_mz.end())-1 : std::distance(pks_mz.begin(), iter_mz);
		
		unsigned int shift = 1;
		//int prev_dist = 0;

		// Experimental candidate base peak.
		RichPeakPtr expr_base_pk = *iter_mz;

		int mode = param.getParameter<int>("mode").first;
		// For confidence estimation, using internal_accuracy.
		double internal_accuracy = param.getParameter<double>("internal_accuracy").first;

		// For peak finding and lambda estimation, using external_accuracy.
		double external_accuracy = param.getParameter<double>("external_accuracy").first;

		// Calculate the mass of the candidate base peak.
		// Notice that there will be mechanism where there is electron capture.
		double mass = calculateMass(expr_base_pk->mz, charge * mode);

		// Create theoretical boundary. The boundary has been adjusted to fit the charge.
		//EnvelopBoundary env_bound = this->createBoundary(mass, charge);
		EnvelopBoundary& env_bound = pk_set.getBoundary();

		//std::cout << "Up Boundary: " << std::endl;
		//env_bound.first.printPeakList<peak_mz>();
		//std::cout << "Down Boundary: " << std::endl;
		//env_bound.second.printPeakList<peak_mz>();

		// Get a copy of the base peak iterator for further move operation.
		//RichPeakListByMZ::iterator iter = iter_mz;
		int stop_flag = 1;

		// Dynamically convert pk_set into vector of envelops.
		std::pair<unsigned int, size_t> shift_count(0,1);
		size_t max_env = 0;

		//std::advance(iter_mz, direction);
		if(direction < 0 && iter_mz == pks_mz.begin())
			return 0;
		std::advance(iter_mz, direction);
		if(direction > 0 && iter_mz == pks_mz.end())
			return 0;

		// TBD: the program should efficiently location the position of most likely peak. instead of sequentially search for it.
		while(1)
		{


			std::cout << "Shift: " << shift << std::endl;

			// Get the boundary peaks at current shift.
			PeakPtr theo_pk1 = env_bound.getUpperBound().getPeakByShift<peak_intensity>(direction * shift);
			PeakPtr theo_pk2 = env_bound.getLowerBound().getPeakByShift<peak_intensity>(direction * shift);

			// No extension any more.
			if(theo_pk1->mz == 0.0 && theo_pk2->mz == 0.0)
				break;

			RichPeakPtr current_pk = *iter_mz;
			std::cout << "Examine peak: " << current_pk->mz << std::endl;

			// Experimental distance from current peak to base peak.
			// Notice that the value might be negative.
			double expr_dist = abs(current_pk->mz - expr_base_pk->mz);

			// Theoretical distance from current peak to base peak. Adjusted for charged peak.
			double theo_dist1 = abs(env_bound.getUpperBound().getMassDifferenceByShift<peak_intensity>(0, shift));
			double theo_dist2 = abs(env_bound.getLowerBound().getMassDifferenceByShift<peak_intensity>(0, shift));

			double max_dist = theo_dist1;
			double min_dist = theo_dist2;

			if(max_dist < min_dist) {
				swap(min_dist, max_dist);
			}

			double error1 = 1e6 * (expr_dist - min_dist)/expr_base_pk->mz;
			double error2 = 1e6 * (expr_dist - max_dist)/expr_base_pk->mz;
			
			if(error1 < -1 * external_accuracy) {
				// Before the shift region: keep moving the iterator.
				// std::advance(iter_mz, direction); continue;
			} else if(error2 > external_accuracy) { 
				// Beyond the shift region: update shift.
				if(stop_flag == 0) {
					shift++; stop_flag = 1; continue;
				} else {
					// break means no missing peak is allowed in the middle. This might be controlled by some parameter.
					stop_flag = 1;
					break;
				}
			} else {
				// A matching peak. Notice the effect of charge state.
				std::cout << "A matching peak!" << std::endl;
				
				if(shift == shift_count.first) {
					shift_count.second++;
				} else {
					// Reset shift_count.
					shift_count = std::make_pair(shift, 1);
				}

				// Update maximum number of envelops.
				if(shift_count.second > max_env)
					max_env = shift_count.second;

				stop_flag = 0;
				// Estimate the confidence of the mz in terms of estimating lambda.
				double diff = max_dist - min_dist;

				// Error window is used for confidence estimation.
				double err_win = internal_accuracy * expr_base_pk->mz * 1e-6;
				double prob = diff/(diff + 2*err_win);

				// Indicate the sign of the error window.
				int err_sign = (theo_dist1 < theo_dist2 ? -1 : 1);

				//: lambda_mz should always be in (0, 1). If lambda is closed to 1, the pattern is closed to no-sulfate boundary, and 0 for high-sulfate boundary.
				double lambda_mz = (expr_dist - theo_dist2+err_sign*err_win)/(theo_dist1 - theo_dist2 + 2*err_sign*err_win);

				// Round the abnormal lambda_mz to the boundary.
				if(lambda_mz > 1) {
					lambda_mz = 1.0;
					prob = 1.0;
				} else if(lambda_mz < 0) {
					lambda_mz = 0.0;
					prob = 1.0;
				}

				// TBD: estimate lambda_abd (within 5%) and delta_lambda.
				// Notice: lambda_abd can be < 0 or > 1.
				double lambda_abd = (current_pk->resolution/expr_base_pk->resolution - theo_pk2->intensity)/(theo_pk1->intensity - theo_pk2->intensity);

				InfoPeakPtr pk_infor = boost::make_shared<InfoPeak>(current_pk->resolution, lambda_mz, lambda_abd, prob);
				// Notice: The abundance information should be initialized during the establish of global lambda value.
				//pk_infor.adjusted_abundance = env_bound.getTheoreticalPeak(lambda_abd, shift).intensity;
				
				pk_set.addPeak(shift, current_pk, pk_infor);
				
			}
			if(direction < 0 && iter_mz == pks_mz.begin())
				break;
			std::advance(iter_mz, direction);
			if(direction > 0 && iter_mz == pks_mz.end())
				break;
		}
		return max_env;
	}
Ejemplo n.º 8
0
	void EnvelopFinder::findNextEnvelops(RichList& island, RichPeakListByResolution::iterator iter_area, unsigned int charge, std::set<EnvelopPtr>& env_set)
	{
		// 1. Find candidate envelops which extend from current peak.
		
		// Project the area iterator into corresponding mz iterator.
		RichPeakListByMZ::iterator iter_mz = island.getPeakContainer().project<peak_mz>(iter_area);

		std::cout << "Identify base peak: " << (*iter_mz)->mz << " Charge: " << charge << std::endl;
		
		int mode = param.getParameter<int>("mode").first;
		double pre_mz = param.getParameter<double>("precursor_mz").first;
		int pre_z = param.getParameter<int>("precursor_charge").first;
		
		// Convert m/z value to corresponding mass. 
		double pre_mass = calculateMass(pre_mz, pre_z * mode);

		// If the calculated mass is larger than precursor mass, there is no need to continue identification.
		double mass = calculateMass((*iter_mz)->mz, charge * mode);
		
		if(mass > pre_mass)
			return;

		std::pair<PeakSet,size_t> pk_set = this->extendPeakSet(island, iter_mz, charge);
		
		if(pk_set.first.getSize()==1)
			return;

    // Container for temporary storage of envelops.
		std::vector<EnvelopPtr> env_store;
		for(size_t i=0; i < pk_set.second; i++) {
			EnvelopPtr env = createEnvelop(charge, pk_set.first.getBoundary());
			env_store.push_back(env);
		}

		// 2. TBD: Estimate the validity of the pk_set.
		// e.g. the overall shifts and the continuity of the shifts.

		// 2.a If the base peak has been reported as a distal peak of other envelops.
		// 2.b If envelops which share the base peak have the same charge 
		// 2.c No event report for the base peak.
		// 2.d no contribution of new peaks.
		// 2.e fitting score is worse than expected.

		// Get the maximum number of envelops.

		// Dynamically convert pk_set into vector of envelops.
		ProtoEnv& peak_information = pk_set.first.getPeakInformation();

		ProtoEnv::iterator pk_iter = peak_information.begin(); 
		// Iterate over all shift, decide if all envelop will share.
		for(; pk_iter != peak_information.end(); )
		{
			int count = peak_information.count(pk_iter->first);
			std::pair<ProtoEnv::iterator, ProtoEnv::iterator> shift_pair = peak_information.equal_range(pk_iter->first);
			ProtoEnv::iterator shift_iter = shift_pair.first;
			ProtoEnv::iterator last_iter = shift_pair.second;
			last_iter--;

			for(size_t i=0; i<env_store.size(); i++)
			{	
				// Clean the definition of the internal structure.
				int shift = shift_iter->first;
				RichPeakPtr pk = shift_iter->second.first;			
				InfoPeakPtr info = shift_iter->second.second;
				// Register the (peak, env) pair, shift and peak info into the envelop reference table.
				InfoPeakPtr info_copy(new InfoPeak(*info));
				std::cout << "Register peak " << pk->mz << "for envelop " << env_store[i]->id << std::endl;
				env_ref.addDictionaryReference(pk, env_store.at(i), shift, info_copy);

				// Non_unique_key.
				if(shift_iter != last_iter)
					shift_iter++;		

			}

			pk_iter = shift_pair.second;
		}

		// Update envelop lambda information for each envelop.
		this->updateEnvelopParameter(env_store);

		// Store the envelops.
		env_set.insert(env_store.begin(), env_store.end());
	}
Ejemplo n.º 9
0
TetrahedronSystem::TetrahedronSystem() 
{
	m_hostTetrahedronVicinityInd = new BaseBuffer;
	m_hostTetrahedronVicinityStart = new BaseBuffer;
	m_hostElementValue = new BaseBuffer;
	create(NTET, NTET * 4, NPNT);
	m_hostElementValue->create(NTET * 4);
    
	float * hv = &hostV()[0];
	
	unsigned i, j;
	float vy = 3.95f;
	float vrx, vry, vrz, vr, vs;
	for(j=0; j < GRDH; j++) {
		for(i=0; i<GRDW; i++) {
		    vs = 1.75f + RandomF01() * 1.5f;
			Vector3F base(9.3f * i, 9.3f * j, 0.f * j);
			Vector3F right = base + Vector3F(1.75f, 0.f, 0.f) * vs;
			Vector3F front = base + Vector3F(0.f, 0.f, 1.75f) * vs;
			Vector3F top = base + Vector3F(0.f, 1.75f, 0.f) * vs;
			if((j&1)==0) {
			    right.y = top.y-.1f;
			}
			else {
			    base.x -= .085f * vs;
			}
			
			vrx = 0.725f * (RandomF01() - .5f);
			vry = 1.f  * (RandomF01() + 1.f)  * vy;
			vrz = 0.732f * (RandomF01() - .5f);
			vr = 0.13f * RandomF01();
			
			addPoint(&base.x);
			hv[0] = vrx + vr;
			hv[1] = vry;
			hv[2] = vrz - vr;
			hv+=3;
			addPoint(&right.x);
			hv[0] = vrx - vr;
			hv[1] = vry;
			hv[2] = vrz + vr;
			hv+=3;
			addPoint(&top.x);
			hv[0] = vrx + vr;
			hv[1] = vry;
			hv[2] = vrz + vr;
			hv+=3;
			addPoint(&front.x);
			hv[0] = vrx - vr;
			hv[1] = vry;
			hv[2] = vrz - vr;
			hv+=3;

			unsigned b = (j * GRDW + i) * 4;
			addTetrahedron(b, b+1, b+2, b+3);		
		}
		vy = -vy;
	}
	setTotalMass(100.f);
    setInitialTotalMass(100.f);
    calculateMass();
    createL2Vicinity();
}