Search in sources :

Example 6 with DoubleByReference

use of com.sun.jna.ptr.DoubleByReference in project UniversalMediaServer by UniversalMediaServer.

the class CoreFoundationTest method testCFNumber.

/**
 * Tests {@link CFNumberRef}.
 *
 * @throws Throwable if an error occurs during the test.
 */
@Test
public void testCFNumber() throws Throwable {
    IntByReference intRef = new IntByReference();
    LongByReference longRef = new LongByReference();
    DoubleByReference doubleRef = new DoubleByReference();
    CFNumberRef cfNumberRef = CFNumberRef.toCFNumberRef((byte) 254);
    assertEquals((byte) 254, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt8Type, CF.CFNumberGetType(cfNumberRef));
    assertFalse(CF.CFNumberIsFloatType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef((short) 31400);
    assertEquals((short) 31400, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt16Type, CF.CFNumberGetType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef('a');
    assertEquals('a', cfNumberRef.getValue().intValue());
    assertEquals(CFNumberType.kCFNumberSInt8Type, CF.CFNumberGetType(cfNumberRef));
    assertFalse(CF.CFNumberIsFloatType(cfNumberRef));
    assertTrue(CF.CFNumberGetValue(cfNumberRef, CFNumberType.kCFNumberSInt32Type, intRef));
    assertEquals('a', intRef.getValue());
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(11.43d);
    assertEquals(11.43d, cfNumberRef.getValue().doubleValue(), 0.0d);
    assertEquals(CFNumberType.kCFNumberFloat64Type, CF.CFNumberGetType(cfNumberRef));
    assertTrue(CF.CFNumberIsFloatType(cfNumberRef));
    assertFalse(CF.CFNumberGetValue(cfNumberRef, CFNumberType.kCFNumberSInt32Type, intRef));
    assertTrue(CF.CFNumberGetValue(cfNumberRef, CFNumberType.kCFNumberFloat64Type, doubleRef));
    assertEquals(11, intRef.getValue());
    assertEquals(11.43d, doubleRef.getValue(), 0.0d);
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(-43.7f);
    assertEquals(-43.7f, cfNumberRef.getValue().floatValue(), 0.0f);
    assertEquals(CFNumberType.kCFNumberFloat32Type, CF.CFNumberGetType(cfNumberRef));
    assertTrue(CF.CFNumberIsFloatType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(Integer.MAX_VALUE);
    assertEquals(Integer.MAX_VALUE, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt32Type, CF.CFNumberGetType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(Integer.MIN_VALUE);
    assertEquals(Integer.MIN_VALUE, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt32Type, CF.CFNumberGetType(cfNumberRef));
    assertFalse(CF.CFNumberIsFloatType(cfNumberRef));
    assertTrue(CF.CFNumberGetValue(cfNumberRef, CFNumberType.kCFNumberSInt32Type, intRef));
    assertEquals(Integer.MIN_VALUE, intRef.getValue());
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(0);
    assertEquals(0, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt32Type, CF.CFNumberGetType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(Long.MAX_VALUE);
    assertEquals(Long.MAX_VALUE, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt64Type, CF.CFNumberGetType(cfNumberRef));
    assertFalse(CF.CFNumberIsFloatType(cfNumberRef));
    assertTrue(CF.CFNumberGetValue(cfNumberRef, CFNumberType.kCFNumberSInt64Type, longRef));
    assertEquals(Long.MAX_VALUE, longRef.getValue());
    CF.CFRelease(cfNumberRef);
    cfNumberRef = CFNumberRef.toCFNumberRef(Long.MIN_VALUE);
    assertEquals(Long.MIN_VALUE, cfNumberRef.getValue());
    assertEquals(CFNumberType.kCFNumberSInt64Type, CF.CFNumberGetType(cfNumberRef));
    CF.CFRelease(cfNumberRef);
}
Also used : DoubleByReference(com.sun.jna.ptr.DoubleByReference) IntByReference(com.sun.jna.ptr.IntByReference) LongByReference(com.sun.jna.ptr.LongByReference) CFNumberRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef) Test(org.junit.Test)

Example 7 with DoubleByReference

use of com.sun.jna.ptr.DoubleByReference in project ffx by mjschnie.

the class ForceFieldEnergyOpenMM method addFixedChargeNonBondedForce.

/**
 * Uses arithmetic mean to define sigma and geometric mean for epsilon.
 */
private void addFixedChargeNonBondedForce() {
    VanDerWaals vdW = super.getVdwNode();
    if (vdW == null) {
        return;
    }
    /**
     * Only 6-12 LJ with arithmetic mean to define sigma and geometric mean
     * for epsilon is supported.
     */
    VanDerWaalsForm vdwForm = vdW.getVDWForm();
    if (vdwForm.vdwType != LENNARD_JONES || vdwForm.radiusRule != ARITHMETIC || vdwForm.epsilonRule != GEOMETRIC) {
        logger.info(format(" VDW Type:         %s", vdwForm.vdwType));
        logger.info(format(" VDW Radius Rule:  %s", vdwForm.radiusRule));
        logger.info(format(" VDW Epsilon Rule: %s", vdwForm.epsilonRule));
        logger.log(Level.SEVERE, String.format(" Unsuppporterd van der Waals functional form."));
        return;
    }
    fixedChargeNonBondedForce = OpenMM_NonbondedForce_create();
    /**
     * OpenMM vdW force requires a diameter (i.e. not radius).
     */
    double radScale = 1.0;
    if (vdwForm.radiusSize == RADIUS) {
        radScale = 2.0;
    }
    /**
     * OpenMM vdw force requires atomic sigma values (i.e. not r-min).
     */
    if (vdwForm.radiusType == R_MIN) {
        radScale /= 1.122462048309372981;
    }
    /**
     * Add particles.
     */
    Atom[] atoms = molecularAssembly.getAtomArray();
    int nAtoms = atoms.length;
    for (int i = 0; i < nAtoms; i++) {
        Atom atom = atoms[i];
        VDWType vdwType = atom.getVDWType();
        double sigma = OpenMM_NmPerAngstrom * vdwType.radius * radScale;
        double eps = OpenMM_KJPerKcal * vdwType.wellDepth;
        double charge = 0.0;
        MultipoleType multipoleType = atom.getMultipoleType();
        if (multipoleType != null && atoms[i].getElectrostatics()) {
            charge = multipoleType.charge;
        }
        OpenMM_NonbondedForce_addParticle(fixedChargeNonBondedForce, charge, sigma, eps);
    }
    /**
     * Define 1-4 scale factors.
     */
    double lj14Scale = vdwForm.getScale14();
    double coulomb14Scale = 1.0 / 1.2;
    ParticleMeshEwald pme = super.getPmeNode();
    Bond[] bonds = super.getBonds();
    if (bonds != null && bonds.length > 0) {
        int nBonds = bonds.length;
        PointerByReference bondArray;
        bondArray = OpenMM_BondArray_create(0);
        for (int i = 0; i < nBonds; i++) {
            Bond bond = bonds[i];
            int i1 = bond.getAtom(0).getXyzIndex() - 1;
            int i2 = bond.getAtom(1).getXyzIndex() - 1;
            OpenMM_BondArray_append(bondArray, i1, i2);
        }
        if (pme != null) {
            coulomb14Scale = pme.getScale14();
        }
        OpenMM_NonbondedForce_createExceptionsFromBonds(fixedChargeNonBondedForce, bondArray, coulomb14Scale, lj14Scale);
        OpenMM_BondArray_destroy(bondArray);
        int num = OpenMM_NonbondedForce_getNumExceptions(fixedChargeNonBondedForce);
        chargeExclusion = new boolean[num];
        vdWExclusion = new boolean[num];
        exceptionChargeProd = new double[num];
        exceptionEps = new double[num];
        IntByReference particle1 = new IntByReference();
        IntByReference particle2 = new IntByReference();
        DoubleByReference chargeProd = new DoubleByReference();
        DoubleByReference sigma = new DoubleByReference();
        DoubleByReference eps = new DoubleByReference();
        for (int i = 0; i < num; i++) {
            OpenMM_NonbondedForce_getExceptionParameters(fixedChargeNonBondedForce, i, particle1, particle2, chargeProd, sigma, eps);
            if (abs(chargeProd.getValue()) > 0.0) {
                chargeExclusion[i] = false;
                exceptionChargeProd[i] = chargeProd.getValue();
            } else {
                exceptionChargeProd[i] = 0.0;
                chargeExclusion[i] = true;
            }
            if (abs(eps.getValue()) > 0.0) {
                vdWExclusion[i] = false;
                exceptionEps[i] = eps.getValue();
            } else {
                vdWExclusion[i] = true;
                exceptionEps[i] = 0.0;
            }
        }
    }
    Crystal crystal = super.getCrystal();
    if (crystal.aperiodic()) {
        OpenMM_NonbondedForce_setNonbondedMethod(fixedChargeNonBondedForce, OpenMM_NonbondedForce_NonbondedMethod.OpenMM_NonbondedForce_NoCutoff);
    } else {
        OpenMM_NonbondedForce_setNonbondedMethod(fixedChargeNonBondedForce, OpenMM_NonbondedForce_NonbondedMethod.OpenMM_NonbondedForce_PME);
        if (pme != null) {
            // Units of the Ewald coefficient are A^-1; Multiply by AngstromsPerNM to convert to (Nm^-1).
            double aEwald = OpenMM_AngstromsPerNm * pme.getEwaldCoefficient();
            int nx = pme.getReciprocalSpace().getXDim();
            int ny = pme.getReciprocalSpace().getYDim();
            int nz = pme.getReciprocalSpace().getZDim();
            OpenMM_NonbondedForce_setPMEParameters(fixedChargeNonBondedForce, aEwald, nx, ny, nz);
        }
        NonbondedCutoff nonbondedCutoff = vdW.getNonbondedCutoff();
        double off = nonbondedCutoff.off;
        double cut = nonbondedCutoff.cut;
        OpenMM_NonbondedForce_setCutoffDistance(fixedChargeNonBondedForce, OpenMM_NmPerAngstrom * off);
        OpenMM_NonbondedForce_setUseSwitchingFunction(fixedChargeNonBondedForce, OpenMM_True);
        if (cut == off) {
            logger.warning(" OpenMM does not properly handle cutoffs where cut == off!");
            if (cut == Double.MAX_VALUE || cut == Double.POSITIVE_INFINITY) {
                logger.info(" Detected infinite or max-value cutoff; setting cut to 1E+40 for OpenMM.");
                cut = 1E40;
            } else {
                logger.info(String.format(" Detected cut %8.4g == off %8.4g; scaling cut to 0.99 of off for OpenMM.", cut, off));
                cut *= 0.99;
            }
        }
        OpenMM_NonbondedForce_setSwitchingDistance(fixedChargeNonBondedForce, OpenMM_NmPerAngstrom * cut);
    }
    OpenMM_NonbondedForce_setUseDispersionCorrection(fixedChargeNonBondedForce, OpenMM_False);
    // OpenMM_Force_setForceGroup(fixedChargeNonBondedForce, 1);
    OpenMM_System_addForce(system, fixedChargeNonBondedForce);
    logger.log(Level.INFO, String.format(" Added fixed charge non-bonded force."));
    GeneralizedKirkwood gk = super.getGK();
    if (gk != null) {
        addCustomGBForce();
    }
}
Also used : DoubleByReference(com.sun.jna.ptr.DoubleByReference) IntByReference(com.sun.jna.ptr.IntByReference) VanDerWaals(ffx.potential.nonbonded.VanDerWaals) GeneralizedKirkwood(ffx.potential.nonbonded.GeneralizedKirkwood) VanDerWaalsForm(ffx.potential.nonbonded.VanDerWaalsForm) MultipoleType(ffx.potential.parameters.MultipoleType) Atom(ffx.potential.bonded.Atom) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint) VDWType(ffx.potential.parameters.VDWType) NonbondedCutoff(ffx.potential.nonbonded.NonbondedCutoff) PointerByReference(com.sun.jna.ptr.PointerByReference) Bond(ffx.potential.bonded.Bond) OpenMM_AmoebaBondForce_addBond(simtk.openmm.AmoebaOpenMMLibrary.OpenMM_AmoebaBondForce_addBond) RestraintBond(ffx.potential.bonded.RestraintBond) OpenMM_CustomBondForce_addBond(simtk.openmm.OpenMMLibrary.OpenMM_CustomBondForce_addBond) OpenMM_HarmonicBondForce_addBond(simtk.openmm.OpenMMLibrary.OpenMM_HarmonicBondForce_addBond) ParticleMeshEwald(ffx.potential.nonbonded.ParticleMeshEwald) Crystal(ffx.crystal.Crystal)

Example 8 with DoubleByReference

use of com.sun.jna.ptr.DoubleByReference in project jSensors by profesorfalken.

the class UnixSensorsManager method addSubFeatures.

private void addSubFeatures(CSensors cSensors, CChip chip, List<CSubFeature> subFeatures) {
    for (final CSubFeature subFeature : subFeatures) {
        addDebugData(String.format("SubFeature type: %d", subFeature.type));
        addDebugData(String.format("SubFeature name: %s", subFeature.name));
        double value = 0.0;
        DoubleByReference pValue = new DoubleByReference(value);
        if (cSensors.sensors_get_value(chip, subFeature.number, pValue) == 0) {
            addDebugData(String.format("SubFeature value: %s", pValue.getValue()));
            if (subFeature.name.endsWith("_input")) {
                addData(String.format("%s", pValue.getValue()));
                break;
            }
        } else {
            addData("Could not retrieve value");
        }
    }
}
Also used : DoubleByReference(com.sun.jna.ptr.DoubleByReference) CSubFeature(com.profesorfalken.jsensors.manager.unix.jna.CSubFeature)

Aggregations

DoubleByReference (com.sun.jna.ptr.DoubleByReference)8 IntByReference (com.sun.jna.ptr.IntByReference)5 Atom (ffx.potential.bonded.Atom)3 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)3 VanDerWaals (ffx.potential.nonbonded.VanDerWaals)3 VanDerWaalsForm (ffx.potential.nonbonded.VanDerWaalsForm)3 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)3 CSubFeature (com.profesorfalken.jsensors.manager.unix.jna.CSubFeature)2 PointerByReference (com.sun.jna.ptr.PointerByReference)2 Crystal (ffx.crystal.Crystal)2 GeneralizedKirkwood (ffx.potential.nonbonded.GeneralizedKirkwood)2 NonbondedCutoff (ffx.potential.nonbonded.NonbondedCutoff)2 MultipoleType (ffx.potential.parameters.MultipoleType)2 VDWType (ffx.potential.parameters.VDWType)2 CChip (com.profesorfalken.jsensors.manager.unix.jna.CChip)1 CFeature (com.profesorfalken.jsensors.manager.unix.jna.CFeature)1 CSensors (com.profesorfalken.jsensors.manager.unix.jna.CSensors)1 DATE (com.sun.jna.platform.win32.OaIdl.DATE)1 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)1 SYSTEMTIME (com.sun.jna.platform.win32.WinBase.SYSTEMTIME)1