use of ffx.realspace.RealSpaceData in project ffx by mjschnie.
the class RefinementEnergy method setLambda.
/**
* {@inheritDoc}
*/
@Override
public void setLambda(double lambda) {
for (MolecularAssembly molecularAssembly : molecularAssemblies) {
ForceFieldEnergy forceFieldEnergy = molecularAssembly.getPotentialEnergy();
forceFieldEnergy.setLambda(lambda);
}
if (data instanceof DiffractionData) {
XRayEnergy xRayEnergy = (XRayEnergy) dataEnergy;
xRayEnergy.setLambda(lambda);
} else if (data instanceof RealSpaceData) {
RealSpaceEnergy realSpaceEnergy = (RealSpaceEnergy) dataEnergy;
realSpaceEnergy.setLambda(lambda);
}
}
use of ffx.realspace.RealSpaceData in project ffx by mjschnie.
the class RefinementEnergy method getdEdXdL.
/**
* {@inheritDoc}
*/
@Override
public void getdEdXdL(double[] gradient) {
double weight = data.getWeight();
if (thermostat != null) {
kTScale = Thermostat.convert / (thermostat.getTargetTemperature() * Thermostat.kB);
}
int assemblysize = molecularAssemblies.length;
/**
* Compute the chemical energy and gradient.
*/
for (int i = 0; i < assemblysize; i++) {
ForceFieldEnergy forcefieldEnergy = molecularAssemblies[i].getPotentialEnergy();
Arrays.fill(gChemical[i], 0.0);
forcefieldEnergy.getdEdXdL(gChemical[i]);
}
for (int i = 0; i < assemblysize; i++) {
for (int j = 0; j < nXYZ; j++) {
gradient[j] += gChemical[i][j];
}
}
/**
* Normalize gradients for multiple-counted atoms.
*/
if (assemblysize > 1) {
for (int i = 0; i < nXYZ; i++) {
gradient[i] /= assemblysize;
}
}
for (int i = 0; i < nXYZ; i++) {
gradient[i] *= kTScale;
}
/**
* Compute the X-ray target energy and gradient.
*/
if (gXray == null || gXray.length != nXYZ) {
gXray = new double[nXYZ];
} else {
for (int j = 0; j < nXYZ; j++) {
gXray[j] = 0.0;
}
}
if (data instanceof DiffractionData) {
XRayEnergy xRayEnergy = (XRayEnergy) dataEnergy;
xRayEnergy.getdEdXdL(gXray);
} else if (data instanceof RealSpaceData) {
RealSpaceEnergy realSpaceEnergy = (RealSpaceEnergy) dataEnergy;
realSpaceEnergy.getdEdXdL(gXray);
}
// Add the chemical and X-ray gradients.
for (int i = 0; i < nXYZ; i++) {
gradient[i] += weight * gXray[i];
}
}
use of ffx.realspace.RealSpaceData in project ffx by mjschnie.
the class RefinementEnergy method getdEdL.
/**
* {@inheritDoc}
*/
@Override
public double getdEdL() {
double dEdL = 0.0;
if (thermostat != null) {
kTScale = Thermostat.convert / (thermostat.getTargetTemperature() * Thermostat.kB);
}
int assemblysize = molecularAssemblies.length;
/**
* Compute the chemical energy and gradient.
*/
for (int i = 0; i < assemblysize; i++) {
ForceFieldEnergy forceFieldEnergy = molecularAssemblies[i].getPotentialEnergy();
double curdEdL = forceFieldEnergy.getdEdL();
dEdL += (curdEdL - dEdL) / (i + 1);
}
dEdL *= kTScale;
double weight = data.getWeight();
if (data instanceof DiffractionData) {
XRayEnergy xRayEnergy = (XRayEnergy) dataEnergy;
dEdL += weight * xRayEnergy.getdEdL();
} else if (data instanceof RealSpaceData) {
RealSpaceEnergy realSpaceEnergy = (RealSpaceEnergy) dataEnergy;
dEdL += weight * realSpaceEnergy.getdEdL();
}
return dEdL;
}
use of ffx.realspace.RealSpaceData in project ffx by mjschnie.
the class Rescore method rescoreSingle.
private File rescoreSingle(File modelFile, RescoreStrategy rscType, DoubleIndexPair[] energies, int i) {
Path filepath = generatePath(modelFile);
if (filepath == null) {
logger.warning(String.format(" Could not generate path to file %s", modelFile.toPath()));
return null;
}
String filename = pwdPath.relativize(filepath).toString();
File retFile = modelFile;
try {
MolecularAssembly assembly = utils.open(filename);
switch(rscType) {
case NO_RESCORE:
logger.warning(" Rescore is being called with rscType = NO_RESCORE");
break;
case ENERGY_EVAL:
break;
case MINIMIZE:
logger.info(String.format("\n Running minimize on %s", filename));
logger.info(String.format(" RMS gradient convergence criteria: %f", eps));
utils.energy(assembly);
utils.minimize(assembly, eps);
String ext = FilenameUtils.getExtension(filename);
ext = ".".concat(ext);
if (resultDir != null) {
filename = FilenameUtils.getBaseName(filename);
filename = FilenameUtils.concat(resultPath.toString(), filename);
} else {
filename = FilenameUtils.removeExtension(filename);
}
filename = filename.concat(fileSuffix).concat(ext);
retFile = new File(filename);
if (ext.toUpperCase().contains("XYZ")) {
utils.saveAsXYZ(assembly, retFile);
} else {
utils.saveAsPDB(assembly, retFile);
}
break;
case XRAY_MIN:
logger.info(String.format("\n Running x-ray minimize on %s", filename));
DiffractionFile diffractionFile = null;
if (diffractionFiles.isEmpty()) {
diffractionFile = new DiffractionFile(assembly, 1.0, false);
diffractionFiles.add(diffractionFile);
}
CompositeConfiguration properties = Keyword.loadProperties(modelFile);
DiffractionData diffractionData = new DiffractionData(assembly, properties, SolventModel.POLYNOMIAL, diffractionFiles.toArray(new DiffractionFile[diffractionFiles.size()]));
diffractionData.scaleBulkFit();
diffractionData.printStats();
utils.energy(assembly);
RefinementMinimize refinementMinimize = new RefinementMinimize(diffractionData, refinementMode);
if (eps < 0.0) {
eps = refinementMinimize.getEps();
}
logger.info(String.format("\n RMS gradient convergence criteria: %8.5f max number of iterations %d", eps, maxiter));
refinementMinimize.minimize(eps, maxiter);
diffractionData.scaleBulkFit();
diffractionData.printStats();
ext = FilenameUtils.getExtension(filename);
ext = ".".concat(ext);
if (resultDir != null) {
filename = FilenameUtils.getBaseName(filename);
filename = FilenameUtils.concat(resultPath.toString(), filename);
} else {
filename = FilenameUtils.removeExtension(filename);
}
filename = filename.concat(fileSuffix);
diffractionData.writeData(filename + ".mtz");
filename = filename.concat(ext);
diffractionData.writeModel(filename);
retFile = new File(filename);
if (diffractionFile != null) {
try {
diffractionFiles.remove(diffractionFile);
} catch (UnsupportedOperationException ex) {
// This should never occur, because diffractionFiles should be of a List type supporting remove(object).
diffractionFiles = new ArrayList<>();
}
}
break;
case RS_MIN:
logger.info(String.format("\n Running real-space minimize on %s", filename));
RealSpaceFile realspaceFile = null;
if (mapFiles.isEmpty()) {
realspaceFile = new RealSpaceFile(assembly);
mapFiles.add(realspaceFile);
}
properties = Keyword.loadProperties(modelFile);
RealSpaceData realspaceData = new RealSpaceData(assembly, properties, new ParallelTeam(), mapFiles.toArray(new RealSpaceFile[mapFiles.size()]));
utils.energy(assembly);
refinementMinimize = new RefinementMinimize(realspaceData, refinementMode);
if (eps < 0.0) {
eps = 1.0;
}
logger.info(String.format("\n RMS gradient convergence criteria: %8.5f max number of iterations %d", eps, maxiter));
refinementMinimize.minimize(eps, maxiter);
ext = FilenameUtils.getExtension(filename);
ext = ".".concat(ext);
if (resultDir != null) {
filename = FilenameUtils.getBaseName(filename);
filename = FilenameUtils.concat(resultPath.toString(), filename);
} else {
filename = FilenameUtils.removeExtension(filename);
}
filename = filename.concat(fileSuffix).concat(ext);
retFile = new File(filename);
if (ext.toUpperCase().contains("XYZ")) {
utils.saveAsXYZ(assembly, retFile);
} else {
utils.saveAsPDB(assembly, retFile);
}
if (realspaceFile != null) {
try {
mapFiles.remove(realspaceFile);
} catch (UnsupportedOperationException ex) {
// This should never occur, because diffractionFiles should be of a List type supporting remove(object).
mapFiles = new ArrayList<>();
}
}
break;
default:
logger.severe(" No valid rescore type: FFX will not continue.");
}
double e = utils.returnEnergy(assembly);
energies[i] = new DoubleIndexPair(i, e);
utils.close(assembly);
} catch (Exception ex) {
logger.warning(String.format(" Exception rescoring on file %s", filename));
logger.info(ex.toString());
}
return retFile;
}
Aggregations