use of ffx.potential.parsers.XYZFilter in project ffx by mjschnie.
the class PotentialsFileOpener method run.
/**
* At present, parses the PDB, XYZ, INT, or ARC file from the constructor
* and creates MolecularAssembly and properties objects.
*/
@Override
public void run() {
int numFiles = allFiles.length;
for (int i = 0; i < numFiles; i++) {
File fileI = allFiles[i];
Path pathI = allPaths[i];
MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
assembly.setFile(fileI);
CompositeConfiguration properties = Keyword.loadProperties(fileI);
ForceFieldFilter 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();
try {
patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
} catch (IOException e) {
logger.log(Level.INFO, " Error loading {0}.", patch);
}
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));
}
}
assembly.setForceField(forceField);
if (new PDBFileFilter().acceptDeep(fileI)) {
filter = new PDBFilter(fileI, assembly, forceField, properties);
} else if (new XYZFileFilter().acceptDeep(fileI)) {
filter = new XYZFilter(fileI, assembly, forceField, properties);
} else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
filter = new INTFilter(fileI, assembly, forceField, properties);
} else {
throw new IllegalArgumentException(String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString()));
}
/* If on-open mutations requested, add them to filter. */
if (mutationsToApply != null && !mutationsToApply.isEmpty()) {
if (!(filter instanceof PDBFilter)) {
throw new UnsupportedOperationException("Applying mutations during open only supported by PDB filter atm.");
}
((PDBFilter) filter).mutate(mutationsToApply);
}
if (filter.readFile()) {
if (!(filter instanceof PDBFilter)) {
Utilities.biochemistry(assembly, filter.getAtomList());
}
filter.applyAtomProperties();
assembly.finalize(true, forceField);
// ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
ForceFieldEnergy energy;
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
assembly.setPotential(energy);
assemblies.add(assembly);
propertyList.add(properties);
if (filter instanceof PDBFilter) {
PDBFilter pdbFilter = (PDBFilter) filter;
List<Character> altLocs = pdbFilter.getAltLocs();
if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
for (Character c : altLocs) {
// Do not report the root conformer.
if (c == ' ') {
continue;
}
altLocString.append(format("(%s) ", c));
}
altLocString.append("]\n");
logger.info(altLocString.toString());
}
/**
* Alternate conformers may have different chemistry, so
* they each need to be their own MolecularAssembly.
*/
for (Character c : altLocs) {
if (c.equals(' ') || c.equals('A')) {
continue;
}
MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
newAssembly.setForceField(assembly.getForceField());
pdbFilter.setAltID(newAssembly, c);
pdbFilter.clearSegIDs();
if (pdbFilter.readFile()) {
String fileName = assembly.getFile().getAbsolutePath();
newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
filter.applyAtomProperties();
newAssembly.finalize(true, assembly.getForceField());
// energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
newAssembly.setPotential(energy);
assemblies.add(newAssembly);
}
}
}
} else {
logger.warning(String.format(" Failed to read file %s", fileI.toString()));
}
}
activeAssembly = assemblies.get(0);
activeProperties = propertyList.get(0);
}
use of ffx.potential.parsers.XYZFilter in project ffx by mjschnie.
the class MolecularDynamics method assemblyInfo.
protected void assemblyInfo() {
assemblies.stream().parallel().forEach((ainfo) -> {
MolecularAssembly mola = ainfo.getAssembly();
CompositeConfiguration aprops = ainfo.props;
File file = mola.getFile();
String filename = FilenameUtils.removeExtension(file.getAbsolutePath());
File archFile = ainfo.archiveFile;
if (archFile == null) {
archFile = new File(filename + ".arc");
ainfo.archiveFile = XYZFilter.version(archFile);
}
if (ainfo.pdbFile == null) {
String extName = FilenameUtils.getExtension(file.getName());
if (extName.toLowerCase().startsWith("pdb")) {
ainfo.pdbFile = file;
} else {
ainfo.pdbFile = new File(filename + ".pdb");
}
}
if (ainfo.xyzFilter == null) {
ainfo.xyzFilter = new XYZFilter(file, mola, mola.getForceField(), aprops);
}
if (ainfo.pdbFilter == null) {
ainfo.pdbFilter = new PDBFilter(ainfo.pdbFile, mola, mola.getForceField(), aprops);
}
});
}
use of ffx.potential.parsers.XYZFilter in project ffx by mjschnie.
the class MainPanel method saveAsXYZ.
/**
* Save the currently selected FFXSystem to disk.
*
* @param file File to save the system to.
* @since 1.0
*/
public void saveAsXYZ(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) {
SystemFilter filter = new XYZFilter(saveFile, system, null, null);
if (filter.writeFile(saveFile, false)) {
// Refresh Panels with the new System name
hierarchy.setActive(system);
activeFilter = filter;
}
}
}
}
use of ffx.potential.parsers.XYZFilter in project ffx by mjschnie.
the class AbstractOSRW method setOptimization.
public void setOptimization(boolean osrwOptimization, MolecularAssembly molAss) {
this.osrwOptimization = osrwOptimization;
this.molecularAssembly = molAss;
File file = molecularAssembly.getFile();
String fileName = FilenameUtils.removeExtension(file.getAbsolutePath());
String ext = FilenameUtils.getExtension(file.getAbsolutePath());
if (systemFilter == null) {
if (ext.toUpperCase().contains("XYZ")) {
optFile = new File(fileName + "_opt.xyz");
systemFilter = new XYZFilter(optFile, molecularAssembly, null, null);
} else {
optFile = new File(fileName + "_opt.pdb");
systemFilter = new PDBFilter(optFile, molecularAssembly, null, null);
}
}
}
use of ffx.potential.parsers.XYZFilter 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;
}
}
}
Aggregations