cern.colt.matrix.DoubleFactory1D Java Examples

The following examples show how to use cern.colt.matrix.DoubleFactory1D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoleculeModifierAndScorer.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
private void init(int numMinDOFs, LinkedHashMap<DegreeOfFreedom,double[]> DOFBounds) {
    
    //collect constraints, and apply fixed DOF valuestrue
    DOFs = new ArrayList<>();
    constraints = new DoubleMatrix1D[] 
        {DoubleFactory1D.dense.make(numMinDOFs), DoubleFactory1D.dense.make(numMinDOFs)};
    
    int minDOFCount = 0;
    
    for(DegreeOfFreedom dof : DOFBounds.keySet()){
        double bounds[] = DOFBounds.get(dof);
        
        if(bounds[0]==bounds[1]){//fixed DOF
            dof.apply(bounds[0]);//apply fixed value
        }
        else {//minimizable DOF: record DOF and constraints for this objective function
            constraints[0].set(minDOFCount, bounds[0]);
            constraints[1].set(minDOFCount, bounds[1]);
            DOFs.add(dof);
            minDOFCount++;
        }
    }
    
    curDOFVals = DoubleFactory1D.dense.make(DOFs.size());
}
 
Example #2
Source File: CCDKernelCuda.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public Minimizer.Result downloadResultSync() {
	
	// allocate space for the result
	int numDofs = dofInfos.size();
	Minimizer.Result result = new Minimizer.Result(DoubleFactory1D.dense.make(numDofs), 0);
	
	// wait for the kernel to finish and download the out buffer
	DoubleBuffer buf = ccdOut.downloadSync();
	
	// copy to the result
	buf.rewind();
	result.energy = buf.get();
	for (int d=0; d<numDofs; d++) {
		result.dofValues.set(d, Math.toDegrees(buf.get()));
	}
	
	return result;
}
 
Example #3
Source File: MoleculeObjectiveFunction.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public MoleculeObjectiveFunction(ParametricMolecule pmol, EnergyFunction efunc) {
	this.pmol = pmol;
	this.efunc = efunc;
	this.curDOFVals = DoubleFactory1D.dense.make(pmol.dofBounds.size());//will be set properly once we evaluate anything

	// init efunc if needed
	if (efunc instanceof EnergyFunction.NeedsInit) {
		((EnergyFunction.NeedsInit)efunc).init(pmol.mol, pmol.dofs, curDOFVals);
	}

	if (efunc instanceof EnergyFunction.DecomposableByDof) {
		efuncsByDof = ((EnergyFunction.DecomposableByDof)efunc).decomposeByDof(pmol.mol, pmol.dofs);
	} else {
		efuncsByDof = null;
	}
}
 
Example #4
Source File: EPICFitter.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
void uniformVoxelSample(int s, DoubleMatrix1D[] sampRel, DoubleMatrix1D[] sampAbs, double[] trueVal,
        ObjectiveFunction of, double[] relMin, double[] relMax){
    //Draw sample # s for generateSamples, filling in trueVal, sampRel, and sampAbs
    //Generate vector relative to minimum
    DoubleMatrix1D dx = DoubleFactory1D.dense.make(numDOFs);
    //and absolute
    DoubleMatrix1D x = DoubleFactory1D.dense.make(numDOFs);

    for(int dof=0; dof<numDOFs; dof++){
        double top = relMax[dof];
        double bottom = relMin[dof];

        dx.set(dof, bottom + Math.random()*(top-bottom));
        x.set(dof, center.get(dof)+dx.get(dof));
    }

    trueVal[s] = of.getValue(x) - minE;
    
    sampRel[s] = dx;
    sampAbs[s] = x;
}
 
Example #5
Source File: MinVolEllipse.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
static DoubleMatrix1D diagMult(DoubleMatrix2D A, DoubleMatrix2D B){
    //Return the diagonal of the product of two matrices
    //A^T and B should have the same dimensions
    int m = A.rows();
    int n = A.columns();
    if(B.rows()!=n || B.columns()!=m){
        throw new Error("Size mismatch in diagMult: A is "+m+"x"+n+
                ", B is "+B.rows()+"x"+B.columns());
    }

    DoubleMatrix1D ans = DoubleFactory1D.dense.make(m);

    for(int i=0; i<m; i++){
        double s = 0;
        for(int k=0; k<n; k++)
            s += A.getQuick(i, k)*B.getQuick(k, i);
        ans.setQuick(i,s);
    }

    return ans;
}
 
Example #6
Source File: VoxelsDeltaG.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
SampleNormalization(ArrayList<DoubleMatrix1D> fullSamples){
    center = DoubleFactory1D.dense.make(numDOFs);
    scaling = DoubleFactory1D.dense.make(numDOFs);
    jacDet = 1;
    
    for(int dofNum=0; dofNum<numDOFs; dofNum++){
        ArrayList<Double> vals = new ArrayList<>();
        int numSamples = fullSamples.size();
        double cen = 0;
        for(DoubleMatrix1D samp : fullSamples){
            vals.add(samp.get(dofNum));
            cen += samp.get(dofNum);
        }
        center.set(dofNum, cen/numSamples);
        Collections.sort(vals);
        //estimate spread using interquartile range
        double sc = vals.get(3*numSamples/4) - vals.get(numSamples/4);
        jacDet *= sc;
        scaling.set(dofNum, sc);
    }
}
 
Example #7
Source File: EPICEnergyFunction.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public ArrayList<Double> allTermValues(){
    //values of all epic terms at current curDOFVals
    ArrayList<Double> ans = new ArrayList<>();
    
    if(curDOFVals==null){
        throw new RuntimeException("ERROR: Trying to evaluate an EPICEnergyFunction "
                + "before assigning it to a vector of DOF values");
    }
    
    for(int termNum=0; termNum<terms.size(); termNum++){
        EPoly term = terms.get(termNum);
        
        DoubleMatrix1D DOFValsForTerm = DoubleFactory1D.dense.make(term.numDOFs);
        for(int DOFCount=0; DOFCount<term.numDOFs; DOFCount++)
            DOFValsForTerm.set( DOFCount, curDOFVals.get(termDOFs.get(termNum).get(DOFCount)) );
        
        double termVal = term.evaluate(DOFValsForTerm, includeMinE, useSharedMolec);
        ans.add(termVal);
    }
    
    return ans;
}
 
Example #8
Source File: QuadraticApproximator.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public QuadraticApproximator(List<Integer> dofBlockIds, List<Integer> dofCounts) {

		this.dofBlockIds = dofBlockIds;
		this.dofCounts = dofCounts;
		this.numDofs = dofCounts.stream().mapToInt(i -> i).sum();
		this.coefficients = DoubleFactory1D.dense.make(1 + numDofs + numDofs*(numDofs + 1)/2);
		this.maxe = 0.0;

		// compute the dof<->block lookup tables
		blockIndicesByDof = new int[numDofs];
		dofOffsetsByBlock = new int[dofBlockIds.size()];
		int n = 0;
		for (int i=0; i<dofBlockIds.size(); i++) {
			dofOffsetsByBlock[i] = n;
			for (int j=0; j<dofCounts.get(i); j++) {
				blockIndicesByDof[n++] = i;
			}
		}
	}
 
Example #9
Source File: ConfSpace.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public MultiTermEnergyFunction getDecomposedMinimizedEnergy(int[] conf, EnergyFunction efunc, String outputPDBFile){
	//minimize the energy of a conformation, within the DOF bounds indicated by conf (a list of RCs)
	//return the minimized energy
	//if outputPDBFile isn't null, then output the minimized conformation to that file

	RCTuple RCs = new RCTuple(conf);
	MoleculeModifierAndScorer energy = new MoleculeModifierAndScorer(efunc,this,RCs);

	DoubleMatrix1D optDOFVals;

	if(energy.getNumDOFs()>0){//there are continuously flexible DOFs to minimize
		Minimizer min = new CCDMinimizer(energy,false);
		optDOFVals = min.minimize().dofValues;
	}
	else//molecule is already in the right, rigid conformation
		optDOFVals = DoubleFactory1D.dense.make(0);

	double minE = energy.getValue(optDOFVals);//this will put m into the minimized conformation
	
	if (outputPDBFile!=null) {
		PDBIO.writeFile(m, "", minE, outputPDBFile);
	}
	
	return (MultiTermEnergyFunction)energy.getEfunc();
}
 
Example #10
Source File: ApproximatorMatrixCalculator.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
private List<Minimizer.Result> sampleRandomly(ParametricMolecule pmol, MoleculeObjectiveFunction f, int numSamples, Random rand) {

		List<Minimizer.Result> samples = new ArrayList<>(numSamples);

		// start with the minimized center point
		samples.add(new SimpleCCDMinimizer(f).minimizeFromCenter());

		// sample randomly
		for (int i=1; i<numSamples; i++) {

			DoubleMatrix1D x = DoubleFactory1D.dense.make(pmol.dofBounds.size());
			for (int d=0; d<pmol.dofBounds.size(); d++) {
				double min = pmol.dofBounds.getMin(d);
				double max = pmol.dofBounds.getMax(d);
				x.set(d, min + rand.nextDouble()*(max - min));
			}

			samples.add(new Minimizer.Result(x, f.getValue(x)));
		}

		// also sample the minimized center point
		samples.add(new SimpleCCDMinimizer(f).minimizeFromCenter());

		return samples;
	}
 
Example #11
Source File: EllipseCoordDOF.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void apply(double paramVal) {				
	if (!initSet) { //set the center as the initial dihedrals
		for (int i=0; i<initVals.length; i++) { dihedrals.get(i).apply(initVals[i]); }
		double[] vals = new double[dihedrals.size()];
		for (int i=0; i<dihedrals.size(); i++) { vals[i] = dihedrals.get(i).getCurVal(); }
		c = DoubleFactory1D.dense.make(vals);
		initSet = true;
	}
			
	int dim = dihedrals.size(); // dimensionality
	double[] o = new double[dim]; //get old dihedrals
	for (int i=0; i<dim; i++) { o[i] = dihedrals.get(i).getCurVal(); }

	et = new EllipseTransform(A, c);
	double[] phi = et.getEllipsoidalCoords(o); // get old polars
	phi[index] = paramVal; //apply transformation
	double[] u = et.getCartesianCoords(phi);
	
	for (int i=0; i<u.length; i++) {
		if (Double.isNaN(u[i])) { u[i] = 0; }
	}
	
	for (int i=0; i<dihedrals.size(); i++) { dihedrals.get(i).apply(u[i]); }
	curVal = paramVal; // set value internally
}
 
Example #12
Source File: EPICEnergyFunction.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public double getEnergy() {
    if(curDOFVals==null){
        throw new RuntimeException("ERROR: Trying to evaluate an EPICEnergyFunction "
                + "before assigning it to a vector of DOF values");
    }
    
    double E = 0;
    for(int termNum=0; termNum<terms.size(); termNum++){
        EPoly term = terms.get(termNum);
        
        DoubleMatrix1D DOFValsForTerm = DoubleFactory1D.dense.make(term.numDOFs);
        for(int DOFCount=0; DOFCount<term.numDOFs; DOFCount++)
            DOFValsForTerm.set( DOFCount, curDOFVals.get(termDOFs.get(termNum).get(DOFCount)) );
        
        double termVal = term.evaluate(DOFValsForTerm, includeMinE, useSharedMolec);
        E += termVal;
    }
    
    return E;
}
 
Example #13
Source File: GaussianLowEnergySampler.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public GaussianLowEnergySampler(double thresh, ObjectiveFunction of, DoubleMatrix1D DOFmin, 
        DoubleMatrix1D DOFmax, DoubleMatrix1D center) {
    this.EPICThresh1 = thresh;
    this.of = of;
    this.DOFmin = DOFmin;
    this.DOFmax = DOFmax;
    this.center = center;
    numDOFs = DOFmin.size();
    
    //OK we need to figure out sigmas based on thresh
    
    
    double sigmaVal = chooseNumSigmas();
    
    //now go along axes to find sigma
    sigmas = DoubleFactory1D.dense.make(numDOFs);
    for(int dofNum=0; dofNum<numDOFs; dofNum++){
                    
        //bound the good region along dofNum axis
        double goodRegionLB = bisectForGoodRegionEnd(dofNum, DOFmin.get(dofNum));
        double goodRegionUB = bisectForGoodRegionEnd(dofNum, DOFmax.get(dofNum));
        
        //sigma will based on the farther of these from center
        double sigma;
        if( goodRegionUB - center.get(dofNum) >= center.get(dofNum) - goodRegionLB ){
            sigma = (goodRegionUB - center.get(dofNum)) / sigmaVal;
        }
        else
            sigma = (center.get(dofNum) - goodRegionLB) / sigmaVal;
        
        sigmas.set(dofNum, sigma);
    }
}
 
Example #14
Source File: ApproximatorMatrixCalculator.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
private List<Minimizer.Result> sampleDensely(ParametricMolecule pmol, MoleculeObjectiveFunction f, int numSamplesPerDof) {

		int numDims = pmol.dofBounds.size();
		int[] dims = new int[numDims];
		Arrays.fill(dims, numSamplesPerDof);

		int numSamples = numSamplesPerDof;
		for (int i=1; i<numDims; i++) {
			numSamples *= numSamplesPerDof;
		}
		numSamples += 1;
		List<Minimizer.Result> samples = new ArrayList<>(numSamples);

		// start with the minimized center point
		samples.add(new SimpleCCDMinimizer(f).minimizeFromCenter());

		// sample points from a dense regular grid
		for (int[] p : new MathTools.GridIterable(dims)) {

			DoubleMatrix1D x = DoubleFactory1D.dense.make(numDims);
			for (int d=0; d<numDims; d++) {
				double min = pmol.dofBounds.getMin(d);
				double max = pmol.dofBounds.getMax(d);
				double xd = min + (max - min)*p[d]/(dims[d] - 1);
				x.set(d, xd);
			}

			samples.add(new Minimizer.Result(x, f.getValue(x)));
		}

		return samples;
	}
 
Example #15
Source File: EllipseTransform.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public double[] getCartesianCoords(double[] polars) {
	if (polars.length==0) { return new double[0]; }
	
	EigenvalueDecomposition evd = new EigenvalueDecomposition(A);
	DoubleMatrix2D Q = evd.getV();
	DoubleMatrix2D L = evd.getD();
	DoubleMatrix2D qT = Q.viewDice().copy();
	Algebra alg = new Algebra();		
	
	int n = polars.length;		
	double radius = polars[0];
	double[] phis = new double[n-1];
	for (int i=1; i<n; i++) { phis[i-1] = polars[i]; }
	
	double[] cartCoords = new double[n];
	for (int i=0; i<n; i++) {
		double prod = 1;
		for (int j=0; j<i; j++) { prod = prod * Math.sin(phis[j]); }
		if (i<n-1) { prod = prod * Math.cos(phis[i]); } 			
		cartCoords[i] = radius*prod;
	}
	
	// transform cartesian coordinates back!
	
	double[] u = new double[cartCoords.length];
	for (int i=0; i<u.length; i++) {
		u[i] = cartCoords[i]*Math.sqrt(L.get(i, i));
	}
	double[] s = alg.mult(Q, DoubleFactory1D.dense.make(u)).toArray();
	double[] x = new double[s.length];
	for (int i=0; i<x.length; i++) { x[i] = s[i] + c.get(i); }
	
	return x;
}
 
Example #16
Source File: ApproximatedObjectiveFunction.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public ApproximatedObjectiveFunction(ObjectiveFunction f, Approximator approximator) {

		if (f.getNumDOFs() != approximator.numDofs()) {
			throw new IllegalArgumentException("number of degrees of freedom don't match!");
		}

		this.f = f;
		this.approximator = approximator;

		x = DoubleFactory1D.dense.make(f.getNumDOFs());
	}
 
Example #17
Source File: SubThreshSampler.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
DoubleMatrix1D getScaleAdaptive(DoubleMatrix1D sp){
    //Get an appropriate scale for sampling around some starting point sp
    /*
    //initially, we'll go about a tenth of the way across the voxel
    //in each dimension
    samplingScale = DOFmax.copy();
    samplingScale.assign(DOFmin,Functions.minus);
    samplingScale.assign( Functions.mult(0.1) );*/
    
    //Let's aim for a scaling based on what dimensions allow more flexibility
    //we'll let the scale in each dimension be ~ the distance we can go from our starting point (current x)
    //in that dimension (sum of farthest we can go in positive and negative directions)
    DoubleMatrix1D ans = DoubleFactory1D.dense.make(numDOFs);
    
    for(int dim=0; dim<numDOFs; dim++){
        
        DoubleMatrix1D y = sp.copy();
        //we'll just try and estimate distances within a factor of two
        double upDist = 1e-6;//how far up we can go in this dimension
        double downDist = 1e-6;//how far down
        
        do {
            upDist*=2;
            y.set(dim, sp.get(dim)+upDist);
        } while(checkValidPt(y));
        
        do {
            downDist*=2;
            y.set(dim, sp.get(dim)-downDist);
        } while(checkValidPt(y));
        
        
        ans.set(dim,(upDist+downDist)/6);//divide by 6 so we can make moves within the allowed region
        //though tuneScale should handle uniform scaling of samplingScale better
        //if not adapativeScale..
    }
    
    return ans;
}
 
Example #18
Source File: ResidueCudaCCDMinimizer.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Minimizer.Result minimizeFromCenter() {

	DoubleMatrix1D x = DoubleFactory1D.dense.make(dihedrals.size());
	for (Dihedral dihedral : dihedrals) {
		x.set(dihedral.d, (dihedral.xdmax + dihedral.xdmin)/2);
	}

	return minimizeFrom(x);
}
 
Example #19
Source File: GaussianLowEnergySampler.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
DoubleMatrix1D nextSample(){//Sample from the distribution
    DoubleMatrix1D ans = DoubleFactory1D.dense.make(numDOFs);
    for(int dofNum=0; dofNum<numDOFs; dofNum++){
        do {
            double x = center.get(dofNum) + sigmas.get(dofNum) * random.nextGaussian();
            ans.set(dofNum, x);
        } while( ans.get(dofNum) < DOFmin.get(dofNum) 
                || ans.get(dofNum) > DOFmax.get(dofNum) );
    }
    
    return ans;
}
 
Example #20
Source File: ObjectiveFunction.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
default DoubleMatrix1D getDOFsCenter() {
	int n = getNumDOFs();
	DoubleMatrix1D x = DoubleFactory1D.dense.make(n);
	for (int d=0; d<n; d++) {
		double xdmin = getConstraints()[0].get(d);
		double xdmax = getConstraints()[1].get(d);
		x.set(d, (xdmin + xdmax)/2);
	}
	return x;
}
 
Example #21
Source File: CudaCCDMinimizer.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Minimizer.Result minimizeFromCenter() {

	DoubleMatrix1D x = DoubleFactory1D.dense.make(dofBounds.size());
	dofBounds.getCenter(x);

	return minimizeFrom(x);
}
 
Example #22
Source File: NewEPICMatrixCalculator.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public EPoly makeEPoly(RCTuple RCs){
    //calculate the EPIC fit for an RC tuple

    if(RCs.pos.size()==2){//pair: need to check for parametric incompatibility
        //If there are DOFs spanning multiple residues, then parametric incompatibility
        //is whether the pair is mathematically possible (i.e. has a well-defined voxel)
        ResidueConf rc1 = searchSpace.positions.get( RCs.pos.get(0) ).resConfs.get( RCs.RCs.get(0) );
        ResidueConf rc2 = searchSpace.positions.get( RCs.pos.get(1) ).resConfs.get( RCs.RCs.get(1) );
        if(rc1.isParametricallyIncompatibleWith(rc2)){
            return null;//impossible combination of RC's
        }
    }
    
    if(pruneMat.isPruned(RCs))
        return null;//pruned tuple...effectively infinite energy
    
    MoleculeModifierAndScorer mof = new MoleculeModifierAndScorer(makeObjectiveFunction(RCs));
    //new MoleculeModifierAndScorer(termE,confSpace,RCs);
     
    DoubleMatrix1D bestDOFVals;

    if(mof.getNumDOFs()>0){//there are continuously flexible DOFs to minimize
        CCDMinimizer ccdMin = new CCDMinimizer(mof,true);
        bestDOFVals = ccdMin.minimize().dofValues;
    }
    else//molecule is already in the right, rigid conformation
        bestDOFVals = DoubleFactory1D.dense.make(0);

    double minEnergy = mof.getValue(bestDOFVals);
    EPoly epicFit = compEPICFit(mof,minEnergy,bestDOFVals,RCs);
    
    EnergyFunction.Tools.cleanIfNeeded(mof.getEfunc());//apparently some of these efuncs can get messy
    return epicFit;
}
 
Example #23
Source File: CCDMinimizer.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public void compInitValsMiddle() {
    //make initial values in the middle of the constraints
    double initVals[] = new double[numDOFs];
    for(int a=0; a<numDOFs; a++)
        initVals[a] = ( DOFmin.get(a) + DOFmax.get(a) ) / 2;

    x = DoubleFactory1D.dense.make(initVals);

    boolean badInit = satisfyNonBoxConstr();

    if(badInit){
        throw new Error("can't find feasible initial point for minimization.  GenCoord types:" + getGenCoordTypes(nonBoxConstrGC));
    }
}
 
Example #24
Source File: MoleculeModifierAndScorer.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
public MoleculeModifierAndScorer(EnergyFunction ef, DoubleMatrix1D[] constr, Molecule m, 
        ArrayList<DegreeOfFreedom> DOFList){
    
    constraints = constr;
    molec = m;
    DOFs = DOFList;
    
    curDOFVals = DoubleFactory1D.dense.make(DOFs.size());
    
    setEfunc(ef);
}
 
Example #25
Source File: FlexLab.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
private static ParametricMolecule addDofs(ParametricMolecule pmol, List<BoundedDof> newDofs) {

		// expand the dofs
		List<DegreeOfFreedom> combinedDofs = new ArrayList<>(pmol.dofs);
		for (BoundedDof bdof : newDofs) {
			combinedDofs.add(bdof.dof);
		}

		// expand the dof bounds
		DoubleMatrix1D mins = DoubleFactory1D.dense.make(pmol.dofs.size() + newDofs.size());
		DoubleMatrix1D maxs = mins.copy();
		for (int i=0; i<pmol.dofs.size(); i++) {
			mins.set(i, pmol.dofBounds.getMin(i));
			maxs.set(i, pmol.dofBounds.getMax(i));
		}
		for (int i=0; i<newDofs.size(); i++) {
			mins.set(i + pmol.dofs.size(), newDofs.get(i).min);
			maxs.set(i + pmol.dofs.size(), newDofs.get(i).max);
		}

		// build a new pmol
		return new ParametricMolecule(
			pmol.mol,
			combinedDofs,
			new ObjectiveFunction.DofBounds(new DoubleMatrix1D[] { mins, maxs })
		);
	}
 
Example #26
Source File: FlexLab.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
private static ParametricMolecule wipeDofs(ParametricMolecule pmol) {
	return new ParametricMolecule(
		pmol.mol,
		Collections.emptyList(),
		new ObjectiveFunction.DofBounds(new DoubleMatrix1D[] {
			DoubleFactory1D.dense.make(0),
			DoubleFactory1D.dense.make(0)
		})
	);
}
 
Example #27
Source File: EPolyPC.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
DoubleMatrix1D toPCBasis(DoubleMatrix1D z){
    return axisCoeffs.zMult(z, DoubleFactory1D.dense.make(numDOFs));
}
 
Example #28
Source File: VoxelSeriesChecker.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
double[] sampleResid(double[][] freeDOFVoxel){
    //draw a sample from the voxel and measure its constr resid and free-DOF resid
    
    //draw free DOFs for sample...
    DoubleMatrix1D sampFreeDOFs = DoubleFactory1D.dense.make(numFreeDOFs);
    
    for(int freeDOF=0; freeDOF<numFreeDOFs; freeDOF++){
        double voxWidth = freeDOFVoxel[1][freeDOF] - freeDOFVoxel[0][freeDOF];
        sampFreeDOFs.set( freeDOF, freeDOFVoxel[0][freeDOF] + Math.random()*voxWidth );
    }
    
    //OK now do full DOFs, placing them in NCoord and CACoord
    int fullDOFCount = 0;
    DoubleMatrix1D fullDOFVals = DoubleFactory1D.dense.make(numFullDOFs);
    
    for(int resNum=1; resNum<numRes; resNum++){
        
        for(int dim=0; dim<3; dim++){
            NCoord[resNum][dim] = evalFullDOF(fullDOFCount,sampFreeDOFs);
            fullDOFVals.set(fullDOFCount, NCoord[resNum][dim]);
            fullDOFCount++;
        }
        
        if(resNum==numRes-1)//no CA variables
            break;
        
        for(int dim=0; dim<3; dim++){
            CACoord[resNum][dim] = evalFullDOF(fullDOFCount,sampFreeDOFs);
            fullDOFVals.set(fullDOFCount, CACoord[resNum][dim]);
            fullDOFCount++;
        }
        
        
    }
    
    //Once N and CA in place, can calc C'.  Use plane projection, to match constr in jac
    for(int resNum=0; resNum<numRes-1; resNum++){
        CCoord[resNum]= pepPlanes[resNum].calcCCoords(CACoord[resNum], NCoord[resNum+1],
                CACoord[resNum+1], true);
    }
    
    //OK now handle add up constraint resids!
    ArrayList<Double> sampConstraintVals = calcConstraintVals();
    
    double constrResid = 0;
    for(int c=0; c<numFullDOFs-numFreeDOFs; c++){
        double dev = sampConstraintVals.get(c) - targetConstraintVals.get(c);
        constrResid += dev*dev;
    }
    
    constrResid /= (numFullDOFs-numFreeDOFs);//normalize resid by # of constraints
    
    
    DoubleMatrix1D freeDOFsCheck = Algebra.DEFAULT.mult(freeDOFMatrix, fullDOFVals);
    freeDOFsCheck.assign(freeDOFCenter, Functions.minus);
    freeDOFsCheck.assign(sampFreeDOFs, Functions.minus);//calc deviation in free DOFs
    double freeDOFResid = freeDOFsCheck.zDotProduct(freeDOFsCheck) / numFreeDOFs;
    
    return new double[] {constrResid, freeDOFResid};
}
 
Example #29
Source File: NewEPICMatrixCalculator.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
private void printFitTests(EPICFitter fitter, RCTuple RCList, double minEnergy,
        MoleculeModifierAndScorer mof, DoubleMatrix1D bestDOFVals, ArrayList<EPoly> series){
    //Do some tests on fit performance, and print the results
    int numDOFs = fitter.numDOFs;

    //TESTING FITS
    System.out.println("RCs: "+RCList.stringListing());
    System.out.println("Minimum energy: "+minEnergy);

    double testScales[] = new double[] { 0.01, 0.5, 5, 100 };//100
    int samplesPerScale = 3;



    double relMax[] = new double[numDOFs];//maximum shifts of degrees of freedom relative to minimum point (startVec)
    double relMin[] = new double[numDOFs];
    DoubleMatrix1D constr[] = mof.getConstraints();
    for(int dof=0; dof<numDOFs; dof++){
        relMax[dof] = constr[1].get(dof) - bestDOFVals.get(dof);
        relMin[dof] = constr[0].get(dof) - bestDOFVals.get(dof);
    }


    for(double scale : testScales){
        for(int s=0; s<samplesPerScale; s++){

            //Generate vector relative to minimum
            double dx[] = new double[numDOFs];
            //and absolute
            DoubleMatrix1D sampAbs = DoubleFactory1D.dense.make(numDOFs);
            for(int dof=0; dof<numDOFs; dof++){
                double top = Math.min(relMax[dof], scale);
                double bottom = Math.max(relMin[dof], -scale);
                dx[dof] = bottom + Math.random()*(top-bottom);
                sampAbs.set(dof, bestDOFVals.get(dof)+dx[dof]);
            }

            double trueVal = mof.getValue(sampAbs) - minEnergy;

            System.out.print("TEST: scale="+scale+" dx=");
            for(int dof=0; dof<numDOFs; dof++)
                System.out.print(dx[dof]+" ");

            System.out.print("TRUE="+trueVal+" FIT=");

            for(EPoly b : series){
                if(b!=null)
                    System.out.print(b.evaluate(sampAbs,false,false)+" ");
            }

            System.out.println();
        }
    }
}
 
Example #30
Source File: TermECalculator.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
private void printFitTests(EPICFitter fitter, RCTuple RCList, double minEnergy,
        MoleculeModifierAndScorer mof, DoubleMatrix1D bestDOFVals, ArrayList<EPoly> series){
    //Do some tests on fit performance, and print the results
    int numDOFs = fitter.numDOFs;

    //TESTING FITS
    System.out.println("RCs: "+RCList.stringListing());
    System.out.println("Minimum energy: "+minEnergy);

    double testScales[] = new double[] { 0.01, 0.5, 5, 100 };//100
    int samplesPerScale = 3;



    double relMax[] = new double[numDOFs];//maximum shifts of degrees of freedom relative to minimum point (startVec)
    double relMin[] = new double[numDOFs];
    DoubleMatrix1D constr[] = mof.getConstraints();
    for(int dof=0; dof<numDOFs; dof++){
        relMax[dof] = constr[1].get(dof) - bestDOFVals.get(dof);
        relMin[dof] = constr[0].get(dof) - bestDOFVals.get(dof);
    }


    for(double scale : testScales){
        for(int s=0; s<samplesPerScale; s++){

            //Generate vector relative to minimum
            double dx[] = new double[numDOFs];
            //and absolute
            DoubleMatrix1D sampAbs = DoubleFactory1D.dense.make(numDOFs);
            for(int dof=0; dof<numDOFs; dof++){
                double top = Math.min(relMax[dof], scale);
                double bottom = Math.max(relMin[dof], -scale);
                dx[dof] = bottom + Math.random()*(top-bottom);
                sampAbs.set(dof, bestDOFVals.get(dof)+dx[dof]);
            }

            double trueVal = mof.getValue(sampAbs) - minEnergy;

            System.out.print("TEST: scale="+scale+" dx=");
            for(int dof=0; dof<numDOFs; dof++)
                System.out.print(dx[dof]+" ");

            System.out.print("TRUE="+trueVal+" FIT=");

            for(EPoly b : series){
                if(b!=null)
                    System.out.print(b.evaluate(sampAbs,false,false)+" ");
            }

            System.out.println();
        }
    }
}