use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class TitrationUtils method titratingMultiresidueFactory.
/**
* Create a MultiResidue from the given Residue by adding its alternated
* protonation state(s) as alternate possibilities.
*/
public static MultiResidue titratingMultiresidueFactory(MolecularAssembly mola, Residue res) {
ForceField ff = mola.getForceField();
Potential potential = mola.getPotentialEnergy();
if (!(potential instanceof ForceFieldEnergy)) {
logger.warning(String.format("TitrationFactory only supported by ForceFieldEnergy potentials."));
throw new IllegalStateException();
}
ForceFieldEnergy ffe = (ForceFieldEnergy) potential;
/* Create new titration state. */
Titration titration = Titration.lookup(res);
String targetName = (titration.protForm != res.getAminoAcid3()) ? titration.protForm.toString() : titration.deprotForm.toString();
int resNumber = res.getResidueNumber();
Residue.ResidueType resType = res.getResidueType();
Residue newRes = new Residue(targetName, resNumber, resType);
/* Wrap both states in a MultiResidue. */
MultiResidue multiRes = new MultiResidue(res, ff, ffe);
Polymer polymer = findResiduePolymer(res, mola);
polymer.addMultiResidue(multiRes);
multiRes.addResidue(newRes);
/* Begin in protonated state by default. */
multiRes.setActiveResidue(titration.protForm);
propagateInactiveResidues(multiRes, false);
ffe.reInit();
return multiRes;
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class MainPanel method saveAsP1.
/**
* Save the currently selected FFXSystem to disk.
*
* @param file File to save the system to.
* @since 1.0
*/
public void saveAsP1(File file) {
FFXSystem system = hierarchy.getActive();
if (system != null && !system.isClosing()) {
File saveFile = file;
if (saveFile == null) {
resetFileChooser();
fileChooser.setCurrentDirectory(pwd);
fileChooser.setFileFilter(xyzFileFilter);
fileChooser.setAcceptAllFileFilterUsed(false);
int result = fileChooser.showSaveDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
saveFile = fileChooser.getSelectedFile();
pwd = saveFile.getParentFile();
}
}
if (saveFile != null) {
XYZFilter filter = new XYZFilter(saveFile, system, null, null);
ForceField forceField = system.getForceField();
final double a = forceField.getDouble(ForceFieldDouble.A_AXIS, 10.0);
final double b = forceField.getDouble(ForceFieldDouble.B_AXIS, a);
final double c = forceField.getDouble(ForceFieldDouble.C_AXIS, a);
final double alpha = forceField.getDouble(ForceFieldDouble.ALPHA, 90.0);
final double beta = forceField.getDouble(ForceFieldDouble.BETA, 90.0);
final double gamma = forceField.getDouble(ForceFieldDouble.GAMMA, 90.0);
final String spacegroup = forceField.getString(ForceFieldString.SPACEGROUP, "P1");
Crystal crystal = new Crystal(a, b, c, alpha, beta, gamma, spacegroup);
if (filter.writeFileAsP1(saveFile, false, crystal)) {
// Refresh Panels with the new System name
hierarchy.setActive(system);
}
activeFilter = filter;
}
}
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class MainPanel method openInit.
/**
* Attempts to load the supplied file
*
* @param files Files to open
* @param commandDescription Description of the command that created this
* file.
* @return a {@link java.lang.Thread} object.
*/
private UIFileOpener openInit(List<File> files, String commandDescription) {
if (files == null) {
return null;
}
File file = new File(FilenameUtils.normalize(files.get(0).getAbsolutePath()));
// Set the Current Working Directory based on this file.
setCWD(file.getParentFile());
// Get "filename" from "filename.extension".
String name = file.getName();
String extension = FilenameUtils.getExtension(name);
// Create the CompositeConfiguration properties.
CompositeConfiguration properties = Keyword.loadProperties(file);
forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
// Create an FFXSystem for this file.
FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
String[] patches = properties.getStringArray("patch");
for (String patch : patches) {
logger.info(" Attempting to read force field patch from " + patch + ".");
CompositeConfiguration patchConfiguration = new CompositeConfiguration();
patchConfiguration.addProperty("parameters", patch);
forceFieldFilter = new ForceFieldFilter(patchConfiguration);
ForceField patchForceField = forceFieldFilter.parse();
forceField.append(patchForceField);
if (RotamerLibrary.addRotPatch(patch)) {
logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
}
}
newSystem.setForceField(forceField);
// Decide what parser to use.
SystemFilter systemFilter = null;
if (xyzFileFilter.acceptDeep(file)) {
// Use the TINKER Cartesian Coordinate File Parser.
systemFilter = new XYZFilter(files, newSystem, forceField, properties);
} else if (intFileFilter.acceptDeep(file)) {
// Use the TINKER Internal Coordinate File Parser.
systemFilter = new INTFilter(files, newSystem, forceField, properties);
} else {
// Use the PDB File Parser.
systemFilter = new PDBFilter(files, newSystem, forceField, properties);
}
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
activeFilter = systemFilter;
// return new UIFileOpener(systemFilter, this);
UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
if (fileOpenerThreads > 0) {
fileOpener.setNThreads(fileOpenerThreads);
}
return fileOpener;
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class MainPanel method openFromPDB.
/**
* Opens a file from the PDB
*/
public void openFromPDB() {
if (openThread != null && openThread.isAlive()) {
return;
}
String code = JOptionPane.showInputDialog("Enter the PDB Identifier (4 characters)", "");
if (code == null) {
return;
}
code = code.toLowerCase().trim();
if (code == null || code.length() != 4) {
return;
}
String fileName = code + ".pdb";
String path = getPWD().getAbsolutePath();
File pdbFile = new File(path + File.separatorChar + fileName);
CompositeConfiguration properties = Keyword.loadProperties(pdbFile);
forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
FFXSystem newSystem = new FFXSystem(pdbFile, "PDB", properties);
newSystem.setForceField(forceField);
if (!pdbFile.exists()) {
String fromURL = pdbForID(code);
pdbFile = downloadURL(fromURL);
if (pdbFile == null || !pdbFile.exists()) {
return;
}
} else {
String message = String.format(" Reading the local copy of the PDB file %s.", pdbFile);
logger.info(message);
}
PDBFilter pdbFilter = new PDBFilter(pdbFile, newSystem, forceField, properties);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
UIFileOpener openFile = new UIFileOpener(pdbFilter, this);
if (fileOpenerThreads > 0) {
openFile.setNThreads(fileOpenerThreads);
}
openThread = new Thread(openFile);
openThread.start();
setPanel(GRAPHICS);
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class MainPanel method openInit.
/**
* Attempts to load the supplied file
*
* @param file File to open
* @param commandDescription Description of the command that created this
* file.
* @return a {@link java.lang.Thread} object.
*/
private UIFileOpener openInit(File file, String commandDescription) {
if (file == null || !file.isFile() || !file.canRead()) {
return null;
}
file = new File(FilenameUtils.normalize(file.getAbsolutePath()));
// Set the Current Working Directory based on this file.
setCWD(file.getParentFile());
// Get "filename" from "filename.extension".
String name = file.getName();
String extension = FilenameUtils.getExtension(name);
/**
* Run a Force Field X script.
*/
if (extension.equalsIgnoreCase("ffx") || extension.equalsIgnoreCase("groovy")) {
ModelingShell shell = getModelingShell();
shell.runFFXScript(file);
boolean shutDown = Boolean.parseBoolean(System.getProperty("ffx.shutDown", "true"));
if (java.awt.GraphicsEnvironment.isHeadless() && shutDown) {
exit();
} else {
return null;
}
}
// Create the CompositeConfiguration properties.
CompositeConfiguration properties = Keyword.loadProperties(file);
// Create an FFXSystem for this file.
FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
// Create a Force Field.
forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
String[] patches = properties.getStringArray("patch");
for (String patch : patches) {
logger.info(" Attempting to read force field patch from " + patch + ".");
CompositeConfiguration patchConfiguration = new CompositeConfiguration();
patchConfiguration.addProperty("parameters", patch);
forceFieldFilter = new ForceFieldFilter(patchConfiguration);
ForceField patchForceField = forceFieldFilter.parse();
forceField.append(patchForceField);
if (RotamerLibrary.addRotPatch(patch)) {
logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
}
}
newSystem.setForceField(forceField);
SystemFilter systemFilter = null;
// Decide what parser to use.
if (xyzFileFilter.acceptDeep(file)) {
// Use the TINKER Cartesian Coordinate File Parser.
systemFilter = new XYZFilter(file, newSystem, forceField, properties);
} else if (intFileFilter.acceptDeep(file)) {
// Use the TINKER Internal Coordinate File Parser.
systemFilter = new INTFilter(file, newSystem, forceField, properties);
} else {
// Use the PDB File Parser.
systemFilter = new PDBFilter(file, newSystem, forceField, properties);
}
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
activeFilter = systemFilter;
UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
if (fileOpenerThreads > 0) {
fileOpener.setNThreads(fileOpenerThreads);
}
return fileOpener;
// return new UIFileOpener(systemFilter, this);
}
Aggregations