use of ffx.potential.parsers.PDBFileFilter 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);
}
Aggregations