/** * Fills a {@link BaseResult} instance with data from the AST. * * @param srcName The identifier for the source of the data. * @param ast The AST to traverse. * @return The filled result instance. */ private BaseResult extractSnapshotData(final String srcName, final CommonTree ast) { final BaseResult result = new DefaultBaseResult(srcName); int atomColCount = 0; Atom curAtom = new DefaultAtom(); @SuppressWarnings("unchecked") final List<CommonTree> eventList = ast.getChildren(); if (eventList == null) { logger.error("Parse failed: no AST children found for source " + srcName); return result; } for (CommonTree curNode : eventList) { switch (curNode.getType()) { case SnapshotLexer.EOF: break; case SnapshotLexer.CPUTIME: result.getCpuTimes().add(processCpuTime(curNode)); break; case SnapshotLexer.TERM: result.getTerminationDates().add(processTermDate(curNode)); break; case SnapshotLexer.MULT: result.setMult(toInt(curNode.getText())); break; case SnapshotLexer.FREQVAL: final Double freqVal = toDouble(curNode.getText()); if (freqVal != null) { result.getFrequencyValues().add(freqVal); } break; case SnapshotLexer.XYZINT: case SnapshotLexer.XYZFLOAT: handleAtom(curNode.getText(), curAtom, atomColCount); atomColCount++; if (atomColCount % ATOM_COL_COUNT == 0) { result.addAtom(curAtom); curAtom = new DefaultAtom(); } break; case SnapshotLexer.ELECENG: result.setElecEn(toDouble(curNode.getText())); break; case SnapshotLexer.FUNCSET: final String[] funcSetSplit = curNode.getText().split("/"); result.setFunctional(funcSetSplit[0]); result.setBasisSet(funcSetSplit[1]); break; case SnapshotLexer.SOLVENT: final String[] solvSplit = curNode.getText().split("="); result.setSolvent(solvSplit[1]); break; case SnapshotLexer.ZPECORR: result.setZpeCorrection(toDouble(curNode.getText())); break; case SnapshotLexer.G298: result.setGibbs298(toDouble(curNode.getText())); break; case SnapshotLexer.H298: result.setEnthalpy298(toDouble(curNode.getText())); break; case SnapshotLexer.CHARGE: result.setCharge(toInt(curNode.getText())); break; case SnapshotLexer.STOI: result.setStoichiometry(curNode.getText()); break; case SnapshotLexer.DIPTOT: result.setDipoleMomentTotal(toDouble(curNode.getText())); break; case SnapshotLexer.NATOMS: result.setAtomCount(toInt(curNode.getText())); break; default: logger.warn(String.format("Unhandled data %s %s", curNode.getType(), curNode.getText())); break; } } return result; }