use of ffx.potential.MolecularAssembly in project ffx by mjschnie.
the class TitrationUtils method openFullyProtonated.
public static MolecularAssembly openFullyProtonated(File structure) {
String name = format("%s-prot", FilenameUtils.removeExtension(structure.getName()));
MolecularAssembly mola = new MolecularAssembly(name);
mola.setFile(structure);
List<Mutation> mutations = new ArrayList<>();
List<Residue> residues = mola.getResidueList();
for (Residue res : residues) {
char chain = res.getChainID();
int resID = res.getResidueNumber();
Titration titration = Titration.lookup(res);
if (res.getAminoAcid3() != titration.protForm) {
String protName = titration.protForm.name();
mutations.add(new PDBFilter.Mutation(chain, resID, protName));
}
}
PotentialsUtils utils = new PotentialsUtils();
return utils.openWithMutations(structure, mutations);
}
use of ffx.potential.MolecularAssembly in project ffx by mjschnie.
the class GraphicsEvents method processMouseEvent.
/**
* <p>
* processMouseEvent</p>
*
* @param evt a {@link java.awt.event.MouseEvent} object.
*/
public void processMouseEvent(MouseEvent evt) {
buttonPress = false;
leftButton = false;
middleButton = false;
rightButton = false;
int mod = evt.getModifiersEx();
if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
buttonPress = true;
}
// Left Button
if ((mod & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
leftButton = true;
}
// Middle Button
if ((mod & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) {
middleButton = true;
}
// Alternatively, map "alt + button1" to the middle button
if ((mod & MouseEvent.ALT_DOWN_MASK) == MouseEvent.ALT_DOWN_MASK) {
if (leftButton) {
middleButton = true;
leftButton = false;
}
}
// Right Button
if ((mod & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
rightButton = true;
}
// Alternatively, map "shift + button1" to the right button
if ((mod & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK) {
if (leftButton) {
rightButton = true;
leftButton = false;
}
}
x = evt.getX();
y = evt.getY();
atom = null;
axisSelected = false;
if (buttonPress) {
// Picking Results
pickCanvas.setShapeLocation(x, y);
// Catch and ignore this until a fix is determined...
try {
pickResult = pickCanvas.pickClosest();
} catch (Exception e) {
pickResult = null;
}
if (pickResult != null) {
SceneGraphPath sgp = pickResult.getSceneGraphPath();
Node node = sgp.getObject();
if (node instanceof Shape3D) {
Shape3D s = (Shape3D) node;
Object o = s.getUserData();
if (o instanceof MolecularAssembly) {
MolecularAssembly sys = (MolecularAssembly) o;
if (pickResult.numIntersections() > 0) {
PickIntersection pi = pickResult.getIntersection(0);
int[] coords = pi.getPrimitiveCoordinateIndices();
atom = sys.getAtomFromWireVertex(coords[0]);
}
} else if (o instanceof Atom) {
atom = (Atom) o;
} else if (o instanceof GraphicsAxis) {
axisSelected = true;
}
}
}
}
}
use of ffx.potential.MolecularAssembly in project ffx by mjschnie.
the class MainPanel method convertWait.
/**
* Converts a non-Force Field X data structure into an array of FFXSystem[].
* Presently does not yet have support for array- or list-based data
* structures, only singular objects.
*
* @param data Outside data structure
* @param file Source file
* @return An array of FFXSystem
*/
public synchronized FFXSystem[] convertWait(Object data, File file) {
if (file == null) {
try {
file = PotentialsDataConverter.getDefaultFile(data);
} catch (FileNotFoundException | IllegalArgumentException ex) {
logger.warning(String.format(" Exception in finding file for data structure: %s", ex.toString()));
return null;
}
}
String name = file.getName();
Thread thread = convert(data, file, null);
while (thread != null && thread.isAlive()) {
try {
wait(1);
} catch (InterruptedException e) {
String message = "Exception waiting for " + name + " to open.";
logger.log(Level.WARNING, message, e);
return null;
}
}
MolecularAssembly[] systems = activeConvFilter.getMolecularAssemblys();
if (systems != null) {
int n = systems.length;
FFXSystem[] ffxSystems = new FFXSystem[n];
FFXSystem[] allSystems = getHierarchy().getSystems();
int total = allSystems.length;
for (int i = 0; i < n; i++) {
ffxSystems[i] = allSystems[total - n + i];
}
return ffxSystems;
} else {
return null;
}
}
use of ffx.potential.MolecularAssembly in project ffx by mjschnie.
the class PDBFilter method readNext.
@Override
public boolean readNext(boolean resetPosition) {
// ^ is beginning of line, \\s+ means "one or more whitespace", (\\d+) means match and capture one or more digits.
Pattern modelPatt = Pattern.compile("^MODEL\\s+(\\d+)");
modelsRead = resetPosition ? 1 : modelsRead + 1;
boolean eof = true;
for (MolecularAssembly system : systems) {
File file = system.getFile();
currentFile = file;
try {
BufferedReader currentReader;
if (readers.containsKey(system)) {
currentReader = readers.get(system);
if (!currentReader.ready()) {
currentReader = new BufferedReader(new FileReader(currentFile));
readers.put(system, currentReader);
}
} else {
currentReader = new BufferedReader(new FileReader(currentFile));
readers.put(system, currentReader);
}
// Skip to appropriate model.
String line = currentReader.readLine();
while (line != null) {
line = line.trim();
Matcher m = modelPatt.matcher(line);
if (m.find()) {
int modelNum = Integer.parseInt(m.group(1));
if (modelNum == modelsRead) {
logger.log(Level.INFO, String.format(" Reading model %d for %s", modelNum, currentFile));
eof = false;
break;
}
}
line = currentReader.readLine();
}
if (eof) {
logger.log(Level.INFO, String.format(" End of file reached for %s", file));
currentReader.close();
return false;
}
// Begin parsing the model.
boolean modelDone = false;
line = currentReader.readLine();
while (line != null) {
line = line.trim();
String recID = line.substring(0, Math.min(6, line.length())).trim();
try {
Record record = Record.valueOf(recID);
boolean hetatm = true;
switch(record) {
// ATOM 2 CA ILE A 16 60.793 72.149 -9.511 1.00 6.91 C
case ATOM:
hetatm = false;
case HETATM:
if (!line.substring(17, 20).trim().equals("HOH")) {
// int serial = Hybrid36.decode(5, line.substring(6, 11));
String name = line.substring(12, 16).trim();
if (name.toUpperCase().contains("1H") || name.toUpperCase().contains("2H") || name.toUpperCase().contains("3H")) {
// VERSION3_2 is presently just a placeholder for "anything non-standard".
fileStandard = VERSION3_2;
}
Character altLoc = line.substring(16, 17).toUpperCase().charAt(0);
if (!altLoc.equals(' ') && !altLoc.equals('A') && !altLoc.equals(currentAltLoc)) {
break;
}
String resName = line.substring(17, 20).trim();
Character chainID = line.substring(21, 22).charAt(0);
List<String> segIDList = segidMap.get(chainID);
if (segIDList == null) {
logger.log(Level.WARNING, String.format(" No " + "known segment ID corresponds to " + "chain ID %s", chainID.toString()));
break;
}
String segID = segIDList.get(0);
if (segIDList.size() > 1) {
logger.log(Level.WARNING, String.format(" " + "Multiple segment IDs correspond to" + "chain ID %s; assuming %s", chainID.toString(), segID));
}
int resSeq = Hybrid36.decode(4, line.substring(22, 26));
double[] d = new double[3];
d[0] = new Double(line.substring(30, 38).trim());
d[1] = new Double(line.substring(38, 46).trim());
d[2] = new Double(line.substring(46, 54).trim());
double occupancy = 1.0;
double tempFactor = 1.0;
Atom newAtom = new Atom(0, name, altLoc, d, resName, resSeq, chainID, occupancy, tempFactor, segID);
newAtom.setHetero(hetatm);
// Check if this is a modified residue.
if (modres.containsKey(resName.toUpperCase())) {
newAtom.setModRes(true);
}
Atom returnedAtom = activeMolecularAssembly.findAtom(newAtom);
if (returnedAtom != null) {
returnedAtom.setXYZ(d);
double[] retXYZ = new double[3];
returnedAtom.getXYZ(retXYZ);
} else {
String message = String.format(" " + "Could not find atom %s in assembly", newAtom.toString());
if (dieOnMissingAtom) {
logger.severe(message);
} else {
logger.warning(message);
}
}
break;
}
case ENDMDL:
case // Technically speaking, END should be at the end of the file, not end of the model.
END:
logger.log(Level.FINE, String.format(" Model %d successfully read", modelsRead));
modelDone = true;
default:
break;
}
} catch (Exception ex) {
// Do nothing; it's not an ATOM/HETATM line.
}
if (modelDone) {
break;
}
line = currentReader.readLine();
}
return true;
} catch (IOException ex) {
logger.info(String.format(" Exception in parsing frame %d of %s:" + " %s", modelsRead, system.toString(), ex.toString()));
}
}
return false;
}
use of ffx.potential.MolecularAssembly in project ffx by mjschnie.
the class PotentialsDataConverter method run.
/**
* Converts the data structure to MolecularAssembly(s).
*/
@Override
public void run() {
if (dataStructure == null || dataType.equals(Utilities.DataType.UNK)) {
throw new IllegalArgumentException("Object passed was not recognized.");
}
assemblies = new ArrayList<>();
propertyList = new ArrayList<>();
switch(dataType) {
case BIOJAVA:
Structure struct = (Structure) dataStructure;
String name = struct.getPDBCode();
CompositeConfiguration properties = Keyword.loadProperties(file);
MolecularAssembly assembly = new MolecularAssembly(name);
assembly.setFile(file);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
assembly.setForceField(forceField);
BiojavaFilter filter = new BiojavaFilter(struct, assembly, forceField, properties);
if (filter.convert()) {
filter.applyAtomProperties();
assembly.finalize(true, forceField);
ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
assembly.setPotential(energy);
assemblies.add(assembly);
propertyList.add(properties);
List<Character> altLocs = filter.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(name);
newAssembly.setForceField(assembly.getForceField());
filter.setAltID(newAssembly, c);
filter.clearSegIDs();
if (filter.convert()) {
String fileName = assembly.getFile().getAbsolutePath();
newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
filter.applyAtomProperties();
newAssembly.finalize(true, assembly.getForceField());
energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
newAssembly.setPotential(energy);
assemblies.add(newAssembly);
properties.addConfiguration(properties);
}
}
} else {
logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
}
activeAssembly = assembly;
activeProperties = properties;
break;
case UNK:
default:
throw new IllegalArgumentException("Object passed was not recognized.");
}
}
Aggregations