Skip to content

Commit 2165a3a

Browse files
committed
Allow isotopes to be shown for pseudo atoms.
1 parent eb76f90 commit 2165a3a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

display/renderbasic/src/main/java/org/openscience/cdk/renderer/generators/standard/StandardAtomGenerator.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,25 @@ private StandardAtomGenerator(Font font, double adjunctSpacing, double scriptSiz
118118
AtomSymbol generateSymbol(IAtomContainer container, IAtom atom, HydrogenPosition position, RendererModel model) {
119119
if (atom instanceof IPseudoAtom) {
120120
IPseudoAtom pAtom = (IPseudoAtom) atom;
121-
if (pAtom.getAttachPointNum() <= 0)
121+
if (pAtom.getAttachPointNum() <= 0) {
122+
if (pAtom.getLabel().equals("*")) {
123+
int mass = unboxSafely(pAtom.getMassNumber(), 0);
124+
int charge = unboxSafely(pAtom.getFormalCharge(), 0);
125+
int hcnt = unboxSafely(pAtom.getImplicitHydrogenCount(), 0);
126+
int nrad = container.getConnectedSingleElectronsCount(atom);
127+
if (mass != 0 || charge != 0 || hcnt != 0) {
128+
return generatePeriodicSymbol(0, hcnt,
129+
mass, charge,
130+
nrad, position);
131+
}
132+
}
122133
return generatePseudoSymbol(accessPseudoLabel(pAtom, "?"), position);
134+
}
123135
else
124136
return null; // attach point drawn in bond generator
125137
} else {
126138
int number = unboxSafely(atom.getAtomicNumber(), Elements.ofString(atom.getSymbol()).number());
127139

128-
if (number == 0) return generatePseudoSymbol("?", position);
129-
130140
// unset the mass if it's the major isotope (could be an option)
131141
Integer mass = atom.getMassNumber();
132142
if (mass != null &&
@@ -363,7 +373,8 @@ AtomSymbol generateAbbreviationSymbol(List<String> tokens, HydrogenPosition posi
363373
AtomSymbol generatePeriodicSymbol(final int number, final int hydrogens, final int mass, final int charge,
364374
final int unpaired, HydrogenPosition position) {
365375

366-
TextOutline element = new TextOutline(Elements.ofNumber(number).symbol(), font);
376+
TextOutline element = number == 0 ? new TextOutline("*", font)
377+
: new TextOutline(Elements.ofNumber(number).symbol(), font);
367378
TextOutline hydrogenAdjunct = defaultHydrogenLabel;
368379

369380
// the hydrogen count, charge, and mass adjuncts are script size
@@ -392,7 +403,7 @@ AtomSymbol generatePeriodicSymbol(final int number, final int hydrogens, final i
392403
if (hydrogens > 0) adjuncts.add(hydrogenAdjunct);
393404
if (hydrogens > 1) adjuncts.add(hydrogenCount);
394405
if (charge != 0 || unpaired > 0) adjuncts.add(chargeAdjunct);
395-
if (mass >= 0) adjuncts.add(massAdjunct);
406+
if (mass > 0) adjuncts.add(massAdjunct);
396407

397408
return new AtomSymbol(element, adjuncts);
398409
}

0 commit comments

Comments
 (0)