All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.lth.immun.chem.IsotopeDistribution Maven / Gradle / Ivy

Go to download

Library for general purpose in silico chemistry, mainly intended for mass spectrometry proteomics computations.

There is a newer version: 1.3.3
Show newest version
package se.lth.immun.chem;

/**
 * Implemented based on
 * 
 * Calculation of isotope distributions in mass spectrometry. A trivial solution for a non-trivial problem
 *  Hugo Kubinyi, 1991
 */
public class IsotopeDistribution {

	public static double PRUNE_LEVEL = 0.000001;
	
	public int m0 = 0;
	public int dm = 1;
	public double[] intensities = {1.0};
	
	public IsotopeDistribution() {}
	
	public void add(IsotopeDistribution x) {
		m0 += x.m0;
		double[] ni 	= new double[dm + x.dm - 1];
		for (int i = 0; i < dm; i++)
			for (int j = 0; j < x.dm; j++) {
				ni[i + j] += intensities[i] * x.intensities[j];
			}
		
		dm = dm + x.dm - 1;
		while (ni[dm-1] < PRUNE_LEVEL)
			dm--;
		intensities = ni;
	}
	
	public IsotopeDistribution copy() {
		IsotopeDistribution i = new IsotopeDistribution();
		i.m0 = m0;
		i.dm = dm;
		i.intensities = new double[intensities.length];
		for (int j = 0; j < intensities.length; j++)
			i.intensities[j] = intensities[j];
		return i;
	}
	
	public IsotopeDistribution mult(int n) {
		if (n == 1)
			return copy();
		
		IsotopeDistribution i = new IsotopeDistribution();
		
		IsotopeDistribution prev = this;
		IsotopeDistribution next = null;

		int k = 1;
		while (k <= n) {
			if ((k & n) != 0)
				i.add(prev);
			next = prev.copy();
			next.add(prev);
			prev = next;
			k = k << 1;
		}
		
		return i;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy