Hi John,
Thanks for the response. My IDrawVisitor is at:
https://github.com/RBVI/chemViz2/blob/master/src/main/java/edu/ucsf/rbvi/chemViz2/internal/view/PaintedShapeVisitor.java
and it returns a list of shapes that I can use with Cytoscape's custom
graphics, which is the only thing I can use besides images, and images
don't scale well.
OK, so I guess the best thing might be to grab copies of
GenerateDepiction.java and Depiction*.java and go from there. I was
thinking the easiest would be to add a method to Depiction
(setDrawVisitor) that would allow me to override the visitor.
Thanks for your help! The images look very, very nice, and I'm sure
that with a little effort I can get the shapes to look equally nice.
-- scooter
On 03/06/2016 01:13 AM, John M wrote:
Ah in that case you'll have to roll on your own I'm afraid but the
code is all there for reaction layout etc. Would be curious to see
your IDrawVisitior do you have a link? It's not impossible to open up
an API point to render an IDrawVisitor but I'm not a huge fan of the
interface but they are used under the surface.
Regards,
John W May
john.wilkinson...@gmail.com <mailto:john.wilkinson...@gmail.com>
On 6 March 2016 at 01:05, Scooter Morris <scoo...@cgl.ucsf.edu
<mailto:scoo...@cgl.ucsf.edu>> wrote:
John,
Thanks -- this works great for creating images for both
reactions and molecules! One question, though. I have a special
Visitor that I use to paint images onto Cytoscape nodes. Using
the new depiction approach, there doesn't seem to be a way to pass
my own IDrawVisitor down to the rendering routines. The draw()
method is protected, and even if it wasn't, it would be quite a
pain to figure out how to create all of the bounds outside of the
Depiction. Ideally, there would be something like
void toVisitor(IDrawVisitor myVisitor)
that would look a lot like toImg(), as far as creation of all of
the transformations and bounding boxes, but would call the
myVisitor visitor instead of the AWTDrawVisitor.
-- scooter
On 03/05/2016 01:51 AM, John M wrote:
Hi Scooter,
This is now much easier, for most use-cases you use the new
DepictionGenerator
<http://cdk.github.io/cdk/1.5/docs/api/index.html?org/openscience/cdk/depict/DepictionGenerator.html>
abstract (module cdk-depict will be bundled but needs to be load
separately). Lots of tweaks you can do but it's a one liner:
|new DepictionGenerator().depict(rxn).writeTo("~/myrxn.svg");|
The web application can show you what it will look like:
http://cdkdepict-openchem.rhcloud.com/depict.html
John
Regards,
John W May
john.wilkinson...@gmail.com <mailto:john.wilkinson...@gmail.com>
On 5 March 2016 at 04:49, Scooter Morris <scoo...@cgl.ucsf.edu
<mailto:scoo...@cgl.ucsf.edu>> wrote:
Hi all,
I've been trying to add reactions to the chemViz2 plugin for
Cytoscape and have been unsuccessful so far. I do get the
something
rendered, but everything is on top of each other and much,
much larger
that I think it should be. Here are the steps I'm taking -- any
direction would be really helpful.
First, I layout the reaction:
static public IReaction layoutReaction(IReaction reaction)
throws
CDKException {
int offset = -10;
// Layout agents
AtomContainerSet agents = new AtomContainerSet();
for (IAtomContainer agent:
reaction.getAgents().atomContainers()) {
IAtomContainer newAgent = layoutMolecule(agent);
agents.addAtomContainer(newAgent);
}
// ??? no setAgents method ???
reaction.getAgents().removeAllAtomContainers();
for (IAtomContainer agent: agents.atomContainers()) {
reaction.addAgent(agent);
}
// Layout reactants
AtomContainerSet reactants = new AtomContainerSet();
for (IAtomContainer reactant:
reaction.getReactants().atomContainers()) {
IAtomContainer newReactant = layoutMolecule(reactant);
GeometryTools.translate2DCenterTo(newReactant, new
Point2d(offset, 0));
offset += 2;
reactants.addAtomContainer(newReactant);
}
reaction.setReactants(reactants);
// Layout Products
offset += 6;
AtomContainerSet products = new AtomContainerSet();
for (IAtomContainer product:
reaction.getProducts().atomContainers()) {
IAtomContainer newProduct = layoutMolecule(product);
GeometryTools.translate2DCenterTo(newProduct, new
Point2d(offset,
0));
offset += 2;
products.addAtomContainer(newProduct);
}
reaction.setProducts(products);
return reaction;
}
where layoutMolecule is the code I'm already using to layout
IAtomContainers and seems to work well.
Then, when I actually do the rendering:
ChemModelRenderer renderer =
getReactionRenderer((Color)background);
ChemModel chemModel = new ChemModel();
ReactionSet rSet = new ReactionSet();
rSet.addReaction(iReaction);
chemModel.setReactionSet(rSet);
if (renderer == null)
return null;
(I tried ReactionRenderer also, but got the same results....)
where getReactionRenderer is:
private static ChemModelRenderer getReactionRenderer(Color
background) {
// generators make the image elements
Font font = new Font("Arial", Font.PLAIN, 24);
ChemModelRenderer renderer =
new ChemModelRenderer(Arrays.asList(new
BasicSceneGenerator(),
new StandardGenerator(font)),
Arrays.asList((IGenerator<IReaction>)new
ReactionSceneGenerator(),
(IGenerator<IReaction>)new ReactionArrowGenerator(),
(IGenerator<IReaction>)new ReactionPlusGenerator()),
new AWTFontManager());
RendererModel model = renderer.getRenderer2DModel();
model.set(StandardGenerator.Visibility.class,
SymbolVisibility.iupacRecommendations());
model.set(StandardGenerator.AtomColor.class, new
CDK2DAtomColors());
model.set(StandardGenerator.StrokeRatio.class, 0.85);
model.set(StandardGenerator.SymbolMarginRatio.class, 4d);
if (background == null)
background = new Color(255,255,255,255);
return renderer;
}
I seem to be missing a major step here since the result is a
mess. Any
suggestions or direction would be helpful. I'm currently
using 1.5.12,
but I've also tried with 1.5.11 to no avail....
-- scooter
------------------------------------------------------------------------------
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
<mailto:Cdk-user@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/cdk-user
------------------------------------------------------------------------------
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user