void AmoebaMultipoleForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 2);
    const AmoebaMultipoleForce& force = *reinterpret_cast<const AmoebaMultipoleForce*>(object);

    node.setIntProperty("nonbondedMethod",                  force.getNonbondedMethod());
    node.setIntProperty("polarizationType",                 force.getPolarizationType());
    //node.setIntProperty("pmeBSplineOrder",                  force.getPmeBSplineOrder());
    //node.setIntProperty("mutualInducedIterationMethod",     force.getMutualInducedIterationMethod());
    node.setIntProperty("mutualInducedMaxIterations",       force.getMutualInducedMaxIterations());

    node.setDoubleProperty("cutoffDistance",                force.getCutoffDistance());
    node.setDoubleProperty("aEwald",                        force.getAEwald());
    node.setDoubleProperty("mutualInducedTargetEpsilon",    force.getMutualInducedTargetEpsilon());
    //node.setDoubleProperty("electricConstant",              force.getElectricConstant());
    node.setDoubleProperty("ewaldErrorTolerance",           force.getEwaldErrorTolerance());

    std::vector<int> gridDimensions;
    force.getPmeGridDimensions(gridDimensions);
    SerializationNode& gridDimensionsNode  = node.createChildNode("MultipoleParticleGridDimension");
    gridDimensionsNode.setIntProperty("d0", gridDimensions[0]).setIntProperty("d1", gridDimensions[1]).setIntProperty("d2", gridDimensions[2]); 

    std::vector<std::string> covalentTypes;
    getCovalentTypes(covalentTypes);

    SerializationNode& particles = node.createChildNode("MultipoleParticles");
    for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumMultipoles()); ii++) {

        int axisType, multipoleAtomZ, multipoleAtomX, multipoleAtomY;
        double charge, thole, dampingFactor, polarity;

        std::vector<double> molecularDipole;
        std::vector<double> molecularQuadrupole;

        force.getMultipoleParameters(ii, charge, molecularDipole, molecularQuadrupole,
                                     axisType, multipoleAtomZ, multipoleAtomX, multipoleAtomY, thole, dampingFactor, polarity);

        SerializationNode& particle    = particles.createChildNode("Particle");
        particle.setIntProperty("axisType", axisType).setIntProperty("multipoleAtomZ", multipoleAtomZ).setIntProperty("multipoleAtomX", multipoleAtomX).setIntProperty("multipoleAtomY", multipoleAtomY);
        particle.setDoubleProperty("charge", charge).setDoubleProperty("thole", thole).setDoubleProperty("damp", dampingFactor).setDoubleProperty("polarity", polarity);

        SerializationNode& dipole      = particle.createChildNode("Dipole");
        dipole.setDoubleProperty("d0", molecularDipole[0]).setDoubleProperty("d1", molecularDipole[1]).setDoubleProperty("d2", molecularDipole[2]);

        SerializationNode& quadrupole  = particle.createChildNode("Quadrupole");
        quadrupole.setDoubleProperty("q0", molecularQuadrupole[0]).setDoubleProperty("q1", molecularQuadrupole[1]).setDoubleProperty("q2", molecularQuadrupole[2]);
        quadrupole.setDoubleProperty("q3", molecularQuadrupole[3]).setDoubleProperty("q4", molecularQuadrupole[4]).setDoubleProperty("q5", molecularQuadrupole[5]);
        quadrupole.setDoubleProperty("q6", molecularQuadrupole[6]).setDoubleProperty("q7", molecularQuadrupole[7]).setDoubleProperty("q8", molecularQuadrupole[8]);

        for (unsigned int jj = 0; jj < covalentTypes.size(); jj++) {
            std::vector< int > covalentMap;
            force.getCovalentMap(ii, static_cast<AmoebaMultipoleForce::CovalentType>(jj), covalentMap);
            addCovalentMap(particle, ii, covalentTypes[jj], covalentMap);
        }
    }
}
Example #2
0
void CustomBondForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 3);
    const CustomBondForce& force = *reinterpret_cast<const CustomBondForce*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    node.setBoolProperty("usesPeriodic", force.usesPeriodicBoundaryConditions());
    node.setStringProperty("energy", force.getEnergyFunction());
    SerializationNode& perBondParams = node.createChildNode("PerBondParameters");
    for (int i = 0; i < force.getNumPerBondParameters(); i++) {
        perBondParams.createChildNode("Parameter").setStringProperty("name", force.getPerBondParameterName(i));
    }
    SerializationNode& globalParams = node.createChildNode("GlobalParameters");
    for (int i = 0; i < force.getNumGlobalParameters(); i++) {
        globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
    }
    SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
    for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
        energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
    }
    SerializationNode& bonds = node.createChildNode("Bonds");
    for (int i = 0; i < force.getNumBonds(); i++) {
        int p1, p2;
        vector<double> params;
        force.getBondParameters(i, p1, p2, params);
        SerializationNode& node = bonds.createChildNode("Bond").setIntProperty("p1", p1).setIntProperty("p2", p2);
        for (int j = 0; j < (int) params.size(); j++) {
            stringstream key;
            key << "param";
            key << j+1;
            node.setDoubleProperty(key.str(), params[j]);
        }
    }
}
Example #3
0
void RMSDForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 0);
    const RMSDForce& force = *reinterpret_cast<const RMSDForce*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    SerializationNode& positionsNode = node.createChildNode("ReferencePositions");
    for (const Vec3& pos : force.getReferencePositions())
       positionsNode.createChildNode("Position").setDoubleProperty("x", pos[0]).setDoubleProperty("y", pos[1]).setDoubleProperty("z", pos[2]);
    SerializationNode& particlesNode = node.createChildNode("Particles");
    for (int i : force.getParticles())
       particlesNode.createChildNode("Particle").setIntProperty("index", i);
}
void AmoebaTorsionTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const AmoebaTorsionTorsionForce& force = *reinterpret_cast<const AmoebaTorsionTorsionForce*>(object);

    // grid[xIdx][yIdx][6 values]

    // value0 = x-Grid value
    // value1 = y-Grid value
    // value2 = F          function value
    // value3 = F_x        partial f wrt x
    // value4 = F_y        partial f wrt y
    // value5 = F_xy       partial f wrt x,y

    SerializationNode& grids = node.createChildNode("TorsionTorsionGrids");
    for (unsigned int kk = 0; kk < static_cast<unsigned int>(force.getNumTorsionTorsionGrids()); kk++) {

        const std::vector< std::vector< std::vector<double> > > grid = force.getTorsionTorsionGrid(kk);

        unsigned int gridCount = 0;
        unsigned int gridYsize =  grid[0].size();
        for (unsigned int ii = 0; ii < grid.size(); ii++) {
            gridCount += grid[ii].size();
        }

        SerializationNode& gridNode = grids.createChildNode("TorsionTorsionGrid");
        for (unsigned int ii = 0; ii < grid.size(); ii++) {
            SerializationNode& gridSerializationRow = gridNode.createChildNode("RowNode");
            gridSerializationRow.setIntProperty("dim", ii);
            for (unsigned int jj = 0; jj < grid[ii].size(); jj++) {
                SerializationNode& gridSerializationColumnNode = gridSerializationRow.createChildNode("ColumnNode");
                gridSerializationColumnNode.setIntProperty("dim", jj);
                unsigned int index = 0;
                gridSerializationColumnNode.setDoubleProperty("x",   grid[ii][jj][index++]);
                gridSerializationColumnNode.setDoubleProperty("y",   grid[ii][jj][index++]);
                gridSerializationColumnNode.setDoubleProperty("f",   grid[ii][jj][index++]);
                gridSerializationColumnNode.setDoubleProperty("fx",  grid[ii][jj][index++]);
                gridSerializationColumnNode.setDoubleProperty("fy",  grid[ii][jj][index++]);
                gridSerializationColumnNode.setDoubleProperty("fxy", grid[ii][jj][index++]);
            }
        }
    }

    SerializationNode& bonds = node.createChildNode("TorsionTorsion");
    for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumTorsionTorsions()); ii++) {
        int particle1, particle2, particle3, particle4, particle5;
        int chiralCheckAtomIndex, gridIndex;
        force.getTorsionTorsionParameters(ii, particle1, particle2, particle3, particle4, particle5, chiralCheckAtomIndex, gridIndex);
        bonds.createChildNode("TorsionTorsion").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setIntProperty("p3", particle3).setIntProperty("p4", particle4).setIntProperty("p5", particle5).setIntProperty("chiralCheckAtomIndex", chiralCheckAtomIndex).setIntProperty("gridIndex", gridIndex);

    }
}
Example #5
0
void StateProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const State& s = *reinterpret_cast<const State*>(object);
    node.setDoubleProperty("time", s.getTime());
    Vec3 a,b,c;
    s.getPeriodicBoxVectors(a,b,c);
    SerializationNode& boxVectorsNode = node.createChildNode("PeriodicBoxVectors");
    boxVectorsNode.createChildNode("A").setDoubleProperty("x", a[0]).setDoubleProperty("y", a[1]).setDoubleProperty("z", a[2]);
    boxVectorsNode.createChildNode("B").setDoubleProperty("x", b[0]).setDoubleProperty("y", b[1]).setDoubleProperty("z", b[2]);
    boxVectorsNode.createChildNode("C").setDoubleProperty("x", c[0]).setDoubleProperty("y", c[1]).setDoubleProperty("z", c[2]);
    try {
        s.getParameters();
        SerializationNode& parametersNode = node.createChildNode("Parameters");
        map<string, double> stateParams = s.getParameters();
        map<string, double>::const_iterator it;
        for (it = stateParams.begin(); it!=stateParams.end();it++) {
            parametersNode.setDoubleProperty(it->first, it->second);
        }
    } catch (const OpenMMException &) {
        // do nothing
    }
    try {
        s.getPotentialEnergy();
        SerializationNode& energiesNode = node.createChildNode("Energies");
        energiesNode.setDoubleProperty("PotentialEnergy", s.getPotentialEnergy());
        energiesNode.setDoubleProperty("KineticEnergy", s.getKineticEnergy());
    } catch (const OpenMMException &) {
        // do nothing
    }
    try {
        s.getPositions();
        SerializationNode& positionsNode = node.createChildNode("Positions");
        vector<Vec3> statePositions = s.getPositions();
        for (int i=0; i<statePositions.size();i++) {
           positionsNode.createChildNode("Position").setDoubleProperty("x", statePositions[i][0]).setDoubleProperty("y", statePositions[i][1]).setDoubleProperty("z", statePositions[i][2]);
        }
    } catch (const OpenMMException &) {
        // do nothing
    }
    try {
        s.getVelocities();
        SerializationNode& velocitiesNode = node.createChildNode("Velocities");
        vector<Vec3> stateVelocities = s.getVelocities();
        for (int i=0; i<stateVelocities.size();i++) {
           velocitiesNode.createChildNode("Velocity").setDoubleProperty("x", stateVelocities[i][0]).setDoubleProperty("y", stateVelocities[i][1]).setDoubleProperty("z", stateVelocities[i][2]);
        }
    } catch (const OpenMMException &) {
        // do nothing
    }
    try {
        s.getForces();
        SerializationNode& forcesNode = node.createChildNode("Forces");
        vector<Vec3> stateForces = s.getForces();
        for (int i=0; i<stateForces.size();i++) {
            forcesNode.createChildNode("Force").setDoubleProperty("x", stateForces[i][0]).setDoubleProperty("y", stateForces[i][1]).setDoubleProperty("z", stateForces[i][2]);
        }
    } catch (const OpenMMException &) {
        // do nothing
    }
}
Example #6
0
void GayBerneForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const GayBerneForce& force = *reinterpret_cast<const GayBerneForce*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    node.setIntProperty("method", (int) force.getNonbondedMethod());
    node.setDoubleProperty("cutoff", force.getCutoffDistance());
    node.setBoolProperty("useSwitchingFunction", force.getUseSwitchingFunction());
    node.setDoubleProperty("switchingDistance", force.getSwitchingDistance());
    SerializationNode& particles = node.createChildNode("Particles");
    for (int i = 0; i < force.getNumParticles(); i++) {
        double sigma, epsilon, sx, sy, sz, ex, ey, ez;
        int xparticle, yparticle;
        force.getParticleParameters(i, sigma, epsilon, xparticle, yparticle, sx, sy, sz, ex, ey, ez);
        particles.createChildNode("Particle").setDoubleProperty("sig", sigma).setDoubleProperty("eps", epsilon).setDoubleProperty("sx", sx)
                .setDoubleProperty("sy", sy).setDoubleProperty("sz", sz).setDoubleProperty("ex", ex).setDoubleProperty("ey", ey).setDoubleProperty("ez", ez)
                .setIntProperty("xparticle", xparticle).setIntProperty("yparticle", yparticle);
    }
    SerializationNode& exceptions = node.createChildNode("Exceptions");
    for (int i = 0; i < force.getNumExceptions(); i++) {
        int particle1, particle2;
        double sigma, epsilon;
        force.getExceptionParameters(i, particle1, particle2, sigma, epsilon);
        exceptions.createChildNode("Exception").setIntProperty("p1", particle1).setIntProperty("p2", particle2).setDoubleProperty("sig", sigma).setDoubleProperty("eps", epsilon);
    }
}
void MonteCarloMembraneBarostatProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const MonteCarloMembraneBarostat& force = *reinterpret_cast<const MonteCarloMembraneBarostat*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    node.setDoubleProperty("pressure", force.getDefaultPressure());
    node.setDoubleProperty("surfaceTension", force.getDefaultSurfaceTension());
    node.setDoubleProperty("temperature", force.getDefaultTemperature());
    node.setIntProperty("xymode", force.getXYMode());
    node.setIntProperty("zmode", force.getZMode());
    node.setIntProperty("frequency", force.getFrequency());
    node.setIntProperty("randomSeed", force.getRandomNumberSeed());
}
void CMAPTorsionForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const CMAPTorsionForce& force = *reinterpret_cast<const CMAPTorsionForce*>(object);
    SerializationNode& maps = node.createChildNode("Maps");
    for (int i = 0; i < force.getNumMaps(); i++) {
        int size;
        vector<double> energy;
        force.getMapParameters(i, size, energy);
        SerializationNode& map = maps.createChildNode("Map").setIntProperty("size", size);
        for (int i = 0; i < (int) energy.size(); i++)
            map.createChildNode("Energy").setDoubleProperty("e", energy[i]);
    }
    SerializationNode& torsions = node.createChildNode("Torsions");
    for (int i = 0; i < force.getNumTorsions(); i++) {
        int map, a1, a2, a3, a4, b1, b2, b3, b4;
        force.getTorsionParameters(i, map, a1, a2, a3, a4, b1, b2, b3, b4);
        torsions.createChildNode("Torsion").setIntProperty("a1", a1).setIntProperty("a2", a2).setIntProperty("a3", a3).setIntProperty("a4", a4).setIntProperty("b1", b1).setIntProperty("b2", b2).setIntProperty("b3", b3).setIntProperty("b4", b4).setIntProperty("map", map);
    }
}
void BrownianIntegratorProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const BrownianIntegrator& integrator = *reinterpret_cast<const BrownianIntegrator*>(object);
    node.setDoubleProperty("stepSize", integrator.getStepSize());
    node.setDoubleProperty("constraintTolerance", integrator.getConstraintTolerance());
    node.setDoubleProperty("temperature", integrator.getTemperature());
    node.setDoubleProperty("friction", integrator.getFriction());
    node.setIntProperty("randomSeed", integrator.getRandomNumberSeed());
}
void AmoebaWcaDispersionForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const AmoebaWcaDispersionForce& force = *reinterpret_cast<const AmoebaWcaDispersionForce*>(object);
    node.setDoubleProperty("Epso",    force.getEpso());
    node.setDoubleProperty("Epsh",    force.getEpsh());
    node.setDoubleProperty("Rmino",   force.getRmino());
    node.setDoubleProperty("Rminh",   force.getRminh());
    node.setDoubleProperty("Awater",  force.getAwater());
    node.setDoubleProperty("Shctd",   force.getShctd());
    node.setDoubleProperty("Dispoff", force.getDispoff());
    node.setDoubleProperty("Slevy",   force.getSlevy());

    SerializationNode& particles = node.createChildNode("WcaDispersionParticles");
    for (unsigned int ii = 0; ii < static_cast<unsigned int>(force.getNumParticles()); ii++) {
        double radius, epsilon;
        force.getParticleParameters( ii,  radius, epsilon );
        particles.createChildNode("Particle").setDoubleProperty("radius", radius).setDoubleProperty("epsilon", epsilon);
    }

}
static void loadGrid(const SerializationNode& grid, std::vector< std::vector< std::vector<double> > >& gridVector) {

    const std::vector<SerializationNode>& gridSerializationRows  = grid.getChildren();
    gridVector.resize(gridSerializationRows.size());

    for (unsigned int ii = 0; ii < gridSerializationRows.size(); ii++) {
        const std::vector<SerializationNode>& gridSerializationColumns  = gridSerializationRows[ii].getChildren();
        gridVector[ii].resize(gridSerializationColumns.size());
        for (unsigned int jj = 0; jj < gridSerializationColumns.size(); jj++) {
            const SerializationNode& gridSerializationColumnNode = gridSerializationColumns[jj];
            gridVector[ii][jj].resize(6);
            gridVector[ii][jj][0] = gridSerializationColumnNode.getDoubleProperty("x");
            gridVector[ii][jj][1] = gridSerializationColumnNode.getDoubleProperty("y");
            gridVector[ii][jj][2] = gridSerializationColumnNode.getDoubleProperty("f");
            gridVector[ii][jj][3] = gridSerializationColumnNode.getDoubleProperty("fx");
            gridVector[ii][jj][4] = gridSerializationColumnNode.getDoubleProperty("fy");
            gridVector[ii][jj][5] = gridSerializationColumnNode.getDoubleProperty("fxy");
        }
    }
}
Example #12
0
void CustomGBForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 2);
    const CustomGBForce& force = *reinterpret_cast<const CustomGBForce*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    node.setIntProperty("method", (int) force.getNonbondedMethod());
    node.setDoubleProperty("cutoff", force.getCutoffDistance());
    SerializationNode& perParticleParams = node.createChildNode("PerParticleParameters");
    for (int i = 0; i < force.getNumPerParticleParameters(); i++) {
        perParticleParams.createChildNode("Parameter").setStringProperty("name", force.getPerParticleParameterName(i));
    }
    SerializationNode& globalParams = node.createChildNode("GlobalParameters");
    for (int i = 0; i < force.getNumGlobalParameters(); i++) {
        globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
    }
    SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
    for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
        energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
    }
    SerializationNode& computedValues = node.createChildNode("ComputedValues");
    for (int i = 0; i < force.getNumComputedValues(); i++) {
        string name, expression;
        CustomGBForce::ComputationType type;
        force.getComputedValueParameters(i, name, expression, type);
        computedValues.createChildNode("Value").setStringProperty("name", name).setStringProperty("expression", expression).setIntProperty("type", (int) type);
    }
    SerializationNode& energyTerms = node.createChildNode("EnergyTerms");
    for (int i = 0; i < force.getNumEnergyTerms(); i++) {
        string expression;
        CustomGBForce::ComputationType type;
        force.getEnergyTermParameters(i, expression, type);
        energyTerms.createChildNode("Term").setStringProperty("expression", expression).setIntProperty("type", (int) type);
    }
    SerializationNode& particles = node.createChildNode("Particles");
    for (int i = 0; i < force.getNumParticles(); i++) {
        vector<double> params;
        force.getParticleParameters(i, params);
        SerializationNode& node = particles.createChildNode("Particle");
        for (int j = 0; j < (int) params.size(); j++) {
            stringstream key;
            key << "param";
            key << j+1;
            node.setDoubleProperty(key.str(), params[j]);
        }
    }
    SerializationNode& exclusions = node.createChildNode("Exclusions");
    for (int i = 0; i < force.getNumExclusions(); i++) {
        int particle1, particle2;
        force.getExclusionParticles(i, particle1, particle2);
        exclusions.createChildNode("Exclusion").setIntProperty("p1", particle1).setIntProperty("p2", particle2);
    }
    SerializationNode& functions = node.createChildNode("Functions");
    for (int i = 0; i < force.getNumTabulatedFunctions(); i++)
        functions.createChildNode("Function", &force.getTabulatedFunction(i)).setStringProperty("name", force.getTabulatedFunctionName(i));
}
void loadCovalentMap(const SerializationNode& map, std::vector< int >& covalentMap) {
    for (unsigned int ii = 0; ii < map.getChildren().size(); ii++) {
        covalentMap.push_back(map.getChildren()[ii].getIntProperty("v"));
    }
}
static void addCovalentMap(SerializationNode& particleExclusions, int particleIndex, std::string mapName, std::vector< int > covalentMap) {
    SerializationNode& map   = particleExclusions.createChildNode(mapName);
    for (unsigned int ii = 0; ii < covalentMap.size(); ii++) {
        map.createChildNode("Cv").setIntProperty("v", covalentMap[ii]);
    }
}
void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 1);
    const CustomNonbondedForce& force = *reinterpret_cast<const CustomNonbondedForce*>(object);
    node.setStringProperty("energy", force.getEnergyFunction());
    node.setIntProperty("method", (int) force.getNonbondedMethod());
    node.setDoubleProperty("cutoff", force.getCutoffDistance());
    SerializationNode& perParticleParams = node.createChildNode("PerParticleParameters");
    for (int i = 0; i < force.getNumPerParticleParameters(); i++) {
        perParticleParams.createChildNode("Parameter").setStringProperty("name", force.getPerParticleParameterName(i));
    }
    SerializationNode& globalParams = node.createChildNode("GlobalParameters");
    for (int i = 0; i < force.getNumGlobalParameters(); i++) {
        globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
    }
    SerializationNode& particles = node.createChildNode("Particles");
    for (int i = 0; i < force.getNumParticles(); i++) {
        vector<double> params;
        force.getParticleParameters(i, params);
        SerializationNode& node = particles.createChildNode("Particle");
        for (int j = 0; j < (int) params.size(); j++) {
            stringstream key;
            key << "param";
            key << j+1;
            node.setDoubleProperty(key.str(), params[j]);
        }
    }
    SerializationNode& exclusions = node.createChildNode("Exclusions");
    for (int i = 0; i < force.getNumExclusions(); i++) {
        int particle1, particle2;
        force.getExclusionParticles(i, particle1, particle2);
        exclusions.createChildNode("Exclusion").setIntProperty("p1", particle1).setIntProperty("p2", particle2);
    }
    SerializationNode& functions = node.createChildNode("Functions");
    for (int i = 0; i < force.getNumFunctions(); i++) {
        string name;
        vector<double> values;
        double min, max;
        force.getFunctionParameters(i, name, values, min, max);
        SerializationNode& node = functions.createChildNode("Function").setStringProperty("name", name).setDoubleProperty("min", min).setDoubleProperty("max", max);
        SerializationNode& valuesNode = node.createChildNode("Values");
        for (int j = 0; j < (int) values.size(); j++)
            valuesNode.createChildNode("Value").setDoubleProperty("v", values[j]);
    }
}
void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode& node) const {
    node.setIntProperty("version", 2);
    const CustomNonbondedForce& force = *reinterpret_cast<const CustomNonbondedForce*>(object);
    node.setIntProperty("forceGroup", force.getForceGroup());
    node.setStringProperty("energy", force.getEnergyFunction());
    node.setIntProperty("method", (int) force.getNonbondedMethod());
    node.setDoubleProperty("cutoff", force.getCutoffDistance());
    node.setBoolProperty("useSwitchingFunction", force.getUseSwitchingFunction());
    node.setDoubleProperty("switchingDistance", force.getSwitchingDistance());
    node.setBoolProperty("useLongRangeCorrection", force.getUseLongRangeCorrection());
    SerializationNode& perParticleParams = node.createChildNode("PerParticleParameters");
    for (int i = 0; i < force.getNumPerParticleParameters(); i++) {
        perParticleParams.createChildNode("Parameter").setStringProperty("name", force.getPerParticleParameterName(i));
    }
    SerializationNode& globalParams = node.createChildNode("GlobalParameters");
    for (int i = 0; i < force.getNumGlobalParameters(); i++) {
        globalParams.createChildNode("Parameter").setStringProperty("name", force.getGlobalParameterName(i)).setDoubleProperty("default", force.getGlobalParameterDefaultValue(i));
    }
    SerializationNode& energyDerivs = node.createChildNode("EnergyParameterDerivatives");
    for (int i = 0; i < force.getNumEnergyParameterDerivatives(); i++) {
        energyDerivs.createChildNode("Parameter").setStringProperty("name", force.getEnergyParameterDerivativeName(i));
    }
    SerializationNode& particles = node.createChildNode("Particles");
    for (int i = 0; i < force.getNumParticles(); i++) {
        vector<double> params;
        force.getParticleParameters(i, params);
        SerializationNode& node = particles.createChildNode("Particle");
        for (int j = 0; j < (int) params.size(); j++) {
            stringstream key;
            key << "param";
            key << j+1;
            node.setDoubleProperty(key.str(), params[j]);
        }
    }
    SerializationNode& exclusions = node.createChildNode("Exclusions");
    for (int i = 0; i < force.getNumExclusions(); i++) {
        int particle1, particle2;
        force.getExclusionParticles(i, particle1, particle2);
        exclusions.createChildNode("Exclusion").setIntProperty("p1", particle1).setIntProperty("p2", particle2);
    }
    SerializationNode& functions = node.createChildNode("Functions");
    for (int i = 0; i < force.getNumTabulatedFunctions(); i++)
        functions.createChildNode("Function", &force.getTabulatedFunction(i)).setStringProperty("name", force.getTabulatedFunctionName(i));

    SerializationNode& interactionGroups = node.createChildNode("InteractionGroups");
    for (int i = 0; i < force.getNumInteractionGroups(); i++) {
        SerializationNode& interactionGroup = interactionGroups.createChildNode("InteractionGroup");
        std::set<int> set1;
        std::set<int> set2;
        force.getInteractionGroupParameters(i, set1, set2);
        SerializationNode& set1node = interactionGroup.createChildNode("Set1");
        for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it)
            set1node.createChildNode("Particle").setIntProperty("index", *it);
        SerializationNode& set2node = interactionGroup.createChildNode("Set2");
        for (std::set<int>::iterator it = set2.begin(); it != set2.end(); ++it)
            set2node.createChildNode("Particle").setIntProperty("index", *it);
    }
}