Re: DWAR file format [message #493 is a reply to message #492] |
Sat, 09 March 2019 21:33 |
thomas
Messages: 715 Registered: June 2014
|
Senior Member |
|
|
you could use something like the following Java method, which reads conformers from an SD-File,
creates a CompoundTableModel, populates it with the conformers, and uses a CompoundTableSaver
to write the table model into a native DataWarrior file.
If you need to write much larger files, this method may not be the appropriate approach, because
of the large memory footprint. I suggest that you contact me on my idorsia e-mail address (see
openmolecules.org about page) to find an optimal solution.
(the following depends on some files of the DataWarrior source code):
public static void createConformerDWARDemo() {
final int ROW_COUNT = 1000;
CompoundTableModel tableModel = new CompoundTableModel();
tableModel.initializeTable(ROW_COUNT, 3);
// this is a hack to prevent nullpointer exception and won't be necessary in the future
tableModel.setDetailHandler(new CompoundTableDetailHandler(tableModel));
final String IDENTIFIER_COLUMN_NAME = "ID";
final String STRUCTURE_COLUMN_NAME = "Structure";
// first column will contain the structure name/ID
tableModel.setColumnName(IDENTIFIER_COLUMN_NAME, 0);
// define second column to contain idcodes
tableModel.setColumnName(STRUCTURE_COLUMN_NAME, 1);
tableModel.setColumnProperty(1, CompoundTableConstants.cColumnPropertySpecialType, CompoundTableConstants.cColumnTypeIDCode);
// define third column to contain the 3D-coordinates and make it a child of the structure column
tableModel.setColumnName(CompoundTableConstants.cColumnType3 DCoordinates, 2);
tableModel.setColumnProperty(2, CompoundTableConstants.cColumnPropertySpecialType, CompoundTableConstants.cColumnType3DCoordinates);
tableModel.setColumnProperty(2, CompoundTableConstants.cColumnPropertyParentColumn, STRUCTURE_COLUMN_NAME);
// read some molecules from an SD-File that should contain 3-dimensional atom coordinates
SDFileParser parser = new SDFileParser("someFileName.sdf");
for (int row=0; row<ROW_COUNT && parser.next(); row++) {
StereoMolecule mol = parser.getMolecule();
Canonizer canonizer = new Canonizer(mol);
String id = "ID-"+(row+1);
String idcode = canonizer.getIDCode();
String coords = canonizer.getEncodedCoordinates();
tableModel.setTotalValueAt(id, row, 0);
tableModel.setTotalValueAt(idcode, row, 1);
tableModel.setTotalValueAt(coords, row, 2);
}
tableModel.finalizeTable(CompoundTableEvent.cSpecifierNoRunt imeProperties, null);
// the new JFrame() is also a hack, which can be replaced by null very soon
CompoundTableSaver saver = new CompoundTableSaver(new JFrame(), tableModel, null);
saver.saveNative(null, new File("someFileName.dwar"), false, false);
}
[Updated on: Sat, 09 March 2019 21:59] Report message to a moderator
|
|
|