Generate a compact element for an atom, such as a circle or a square,
rather than text element.

@param atom the atom to generate the compact element for
@param model the renderer model
@return a compact rendering element
2998
public IRenderingElement generateCompactElement(IAtom atom, RendererModel model) {
        Point2d point = atom.getPoint2d();
        double radius = (Double) model.get(AtomRadius.class) / model.getParameter(Scale.class).getValue();
        double distance = 2 * radius;
        if (model.get(CompactShape.class) == Shape.SQUARE) {
            return new RectangleElement(point.x - radius, point.y - radius, distance, distance, true, getAtomColor(
                    atom, model));
        } else {
            return new OvalElement(point.x, point.y, radius, true, getAtomColor(atom, model));
        }
    }
537834
IRenderingElement generateSgroups(IAtomContainer container, AtomSymbol[] symbols) {

        ElementGroup result = new ElementGroup();
        List<Sgroup> sgroups = container.getProperty(CDKConstants.CTAB_SGROUPS);

        if (sgroups == null || sgroups.isEmpty())
            return result;

        Map<IAtom, AtomSymbol> symbolMap = new HashMap<>();
        for (int i = 0; i < symbols.length; i++) {
            if (symbols[i] != null)
                symbolMap.put(container.getAtom(i), symbols[i]);
        }

        for (Sgroup sgroup : sgroups) {

            switch (sgroup.getType()) {
                case CtabAbbreviation:
                    result.add(generateAbbreviationSgroup(container, sgroup));
                    break;
                case CtabMultipleGroup:
                    result.add(generateMultipleSgroup(sgroup, symbolMap));
                    break;
                case CtabAnyPolymer:
                case CtabMonomer:
                case CtabCrossLink:
                case CtabCopolymer:
                case CtabStructureRepeatUnit:
                case CtabMer:
                case CtabGraft:
                case CtabModified:
                    result.add(generatePolymerSgroup(sgroup, symbolMap));
                    break;
                case CtabComponent:
                case CtabMixture:
                case CtabFormulation:
                    result.add(generateMixtureSgroup(sgroup));
                    break;
                case CtabGeneric:
                    // not strictly a polymer but okay to draw as one
                    result.add(generatePolymerSgroup(sgroup, null));
                    break;
            }
        }

        return result;
    }
1219949
def flatten_model(model):
    
    yield model
    if isinstance(model, (TranslucentBinder, Binder,)):
        for m in model:
            # yield from flatten_model(m)
            for x in flatten_model(m):
                yield x
963572
function (e, ef) {

/*Line 118 - 'AtomForm.js' */                if (!ef)
/*Line 119 - 'AtomForm.js' */                    ef = $(e).data("field-error");

/*Line 121 - 'AtomForm.js' */                var ctrl = e.atomControl;
/*Line 122 - 'AtomForm.js' */                var val = null;
/*Line 123 - 'AtomForm.js' */                var skip = false;
/*Line 124 - 'AtomForm.js' */                if (!ctrl) {
/*Line 125 - 'AtomForm.js' */                    if ((/input|select|textarea/i).test(e.nodeName)) {
/*Line 126 - 'AtomForm.js' */                        val = $(e).val();
/*Line 127 - 'AtomForm.js' */                    } else {
/*Line 128 - 'AtomForm.js' */                        skip = true;
/*Line 129 - 'AtomForm.js' */                    }
/*Line 130 - 'AtomForm.js' */                } else {
/*Line 131 - 'AtomForm.js' */                    if (ctrl.constructor == WebAtoms.AtomFormField) {
/*Line 132 - 'AtomForm.js' */                        return ctrl.validate();
/*Line 133 - 'AtomForm.js' */                    }
/*Line 134 - 'AtomForm.js' */                    val = AtomBinder.getValue(ctrl, "value");
/*Line 135 - 'AtomForm.js' */                }

/*Line 137 - 'AtomForm.js' */                if (!skip) {

/*Line 139 - 'AtomForm.js' */                    var req = AtomUI.attr(e,"atom-required");
/*Line 140 - 'AtomForm.js' */                    if (req && !val) {
/*Line 141 - 'AtomForm.js' */                        // error...
/*Line 142 - 'AtomForm.js' */                        AtomProperties.text(ef, "Required");
/*Line 143 - 'AtomForm.js' */                        $(e).addClass("atom-data-error");
/*Line 144 - 'AtomForm.js' */                        return false;
/*Line 145 - 'AtomForm.js' */                    }


/*Line 148 - 'AtomForm.js' */                    var re = AtomUI.attr(e, "atom-regex");
/*Line 149 - 'AtomForm.js' */                    if (!re) {
/*Line 150 - 'AtomForm.js' */                        var dt = AtomUI.attr(e, "atom-data-type");
/*Line 151 - 'AtomForm.js' */                        if (dt) {
/*Line 152 - 'AtomForm.js' */                            switch (dt) {
/*Line 153 - 'AtomForm.js' */                                case "email":
/*Line 154 - 'AtomForm.js' */                                    re = /^(([^<>()\[\]\\.,;:\s@\"]+(\.[^<>()\[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
/*Line 155 - 'AtomForm.js' */                                    break;
/*Line 156 - 'AtomForm.js' */                            }
/*Line 157 - 'AtomForm.js' */                        }
/*Line 158 - 'AtomForm.js' */                    } else {
/*Line 159 - 'AtomForm.js' */                        re = eval("(" + re + ")");
/*Line 160 - 'AtomForm.js' */                    }

/*Line 162 - 'AtomForm.js' */                    if (re) {
/*Line 163 - 'AtomForm.js' */                        if (!re.test(val)) {
/*Line 164 - 'AtomForm.js' */                            $(ef).text("Invalid");
/*Line 165 - 'AtomForm.js' */                            $(e).addClass("atom-data-error");
/*Line 166 - 'AtomForm.js' */                            return false;
/*Line 167 - 'AtomForm.js' */                        }
/*Line 168 - 'AtomForm.js' */                    }

/*Line 170 - 'AtomForm.js' */                    $(ef).text("");
/*Line 171 - 'AtomForm.js' */                    $(e).removeClass("atom-data-error");
/*Line 172 - 'AtomForm.js' */                }

/*Line 174 - 'AtomForm.js' */                // return for every children??
/*Line 175 - 'AtomForm.js' */                var ae = new ChildEnumerator(e);
/*Line 176 - 'AtomForm.js' */                var isValid = true;
/*Line 177 - 'AtomForm.js' */                while (ae.next()) {
/*Line 178 - 'AtomForm.js' */                    if (!this.validate(ae.current(), ef)) {
/*Line 179 - 'AtomForm.js' */                        isValid = false;
/*Line 180 - 'AtomForm.js' */                    }
/*Line 181 - 'AtomForm.js' */                }

/*Line 183 - 'AtomForm.js' */                return isValid;
/*Line 184 - 'AtomForm.js' */            }
915542
private Atom convertAtom(AtomSite atom){


		Atom a = new AtomImpl();

		a.setPDBserial(Integer.parseInt(atom.getId()));
		a.setName(atom.getLabel_atom_id());

		double x = Double.parseDouble (atom.getCartn_x());
		double y = Double.parseDouble (atom.getCartn_y());
		double z = Double.parseDouble (atom.getCartn_z());
		a.setX(x);
		a.setY(y);
		a.setZ(z);

		float occupancy = Float.parseFloat (atom.getOccupancy());
		a.setOccupancy(occupancy);

		float temp = Float.parseFloat (atom.getB_iso_or_equiv());
		a.setTempFactor(temp);

		String alt = atom.getLabel_alt_id();
		if (( alt != null ) && ( alt.length() > 0) && (! alt.equals("."))){
			a.setAltLoc(new Character(alt.charAt(0)));
		} else {
			a.setAltLoc(new Character(' '));
		}

		Element element = Element.R;
		try {
			element = Element.valueOfIgnoreCase(atom.getType_symbol());
		}  catch (IllegalArgumentException e) {
			logger.info("Element {} was not recognised as a BioJava-known element, the element will be represented as the generic element {}", atom.getType_symbol(), Element.R.name());
		}
		a.setElement(element);

		return a;

	}
1004713
AtomSymbol generatePseudoSymbol(String label, HydrogenPosition position) {

        final Font italicFont = font.deriveFont(Font.BOLD)
                                    .deriveFont(Font.ITALIC);
        List<TextOutline> outlines = new ArrayList<>(3);

        int beg = 0;
        int pos = 0;
        int len = label.length();

        // upper case followed by lower case
        while (pos < len && isUpperCase(label.charAt(pos)))
            pos++;
        if (label.charAt(0) != 'R') // Ar is not A^r but 'Ra' is R^a etc
            while (pos < len && isLowerCase(label.charAt(pos)))
                pos++;

        if (pos > beg) {
            outlines.add(new TextOutline(label.substring(beg, pos), italicFont));
            beg = pos;
            // 2a etc.
            while (pos < len && isDigit(label.charAt(pos)))
                pos++;
            while (pos < len && isLowerCase(label.charAt(pos)))
                pos++;

            if (pos > beg) {
                TextOutline outline = new TextOutline(label.substring(beg, pos), italicFont);
                outline = outline.resize(scriptSize, scriptSize);
                outline = positionSuperscript(outlines.get(0), outline);
                outlines.add(outline);
            }

            int numPrimes = 0;
            PRIMES:
            while (pos < len) {
                switch (label.charAt(pos)) {
                    case '\'': numPrimes++; break;
                    case '`': numPrimes++;  break;
                    case '‘': numPrimes++;  break;
                    case '’': numPrimes++;  break;
                    case '‛': numPrimes++;  break;
                    case '“': numPrimes+=2; break;
                    case '”': numPrimes+=2; break;
                    case '′': numPrimes++;  break;
                    case '″': numPrimes+=2; break;
                    case '‴': numPrimes+=3; break;
                    case '⁗': numPrimes+=4; break;
                    case '‵': numPrimes++;  break;
                    case '‶': numPrimes+=2; break;
                    case '‷': numPrimes+=3; break;
                    case '´': numPrimes++;  break;
                    case 'ˊ': numPrimes++;  break;
                    case '́': numPrimes++;  break;
                    case '˝': numPrimes+=2; break;
                    case '̋': numPrimes+=2; break;
                    default: break PRIMES;
                }
                pos++;
            }

            if (pos < len) {
                return new AtomSymbol(new TextOutline(label, italicFont), Collections.<TextOutline>emptyList());
            } else {
                TextOutline outline = null;
                TextOutline ref = outlines.get(outlines.size()-1);
                switch (numPrimes) {
                    case 0: break;
                    case 1: outline = new TextOutline("′", font); break;
                    case 2: outline = new TextOutline("″", font); break;
                    case 3: outline = new TextOutline("‴", font); break;
                    default:
                        String lab = "";
                        while (numPrimes-->0)
                            lab += "′";
                        outline = new TextOutline(lab, font);
                        break;
                }
                if (outline != null) {
                    if (outlines.size() > 1)
                        outline = outline.resize(scriptSize, scriptSize);
                    outline = positionSuperscript(ref, outline);
                    outlines.add(outline);
                }
            }

            // line up text
            for (int i = 1; i < outlines.size(); i++) {
                TextOutline ref = outlines.get(i - 1);
                TextOutline curr = outlines.get(i);
                outlines.set(i, positionAfter(ref, curr));
            }

            return new AtomSymbol(outlines.get(0),
                                  outlines.subList(1, outlines.size()));
        } else {
            return new AtomSymbol(new TextOutline(label, italicFont), Collections.<TextOutline>emptyList());
        }
    }
143791
public Blacklist generateBlacklist(Model model)
	{
		Blacklist blacklist = new Blacklist();

		// populate the blacklist

		for (SmallMoleculeReference smr : model.getObjects(SmallMoleculeReference.class))
		{
			String name = smr.getDisplayName();
			if (name == null) continue;
			name = name.toLowerCase();

			if (knownNames.containsKey(name))
			{
				blacklist.addEntry(smr.getUri(), 1, knownNames.get(name));

				for (SimplePhysicalEntity spe : smr.getEntityReferenceOf())
				{
					blacklist.addEntry(spe.getUri(), 1, knownNames.get(name));
				}
			}
		}

		return blacklist;
	}
1374591
public void render(String templateName, Map<String, Object> model) {
        send(renderToString(templateName, model));
    }
136025
public static <T> TextArea<T> newTextArea(final String id, final IModel<T> model)
	{
		final TextArea<T> textArea = new TextArea<>(id, model);
		textArea.setOutputMarkupId(true);
		return textArea;
	}
571068
public static final void transform (Atom atom, Matrix4d m) {

		Point3d p = new Point3d(atom.getX(),atom.getY(),atom.getZ());
		m.transform(p);

		atom.setX(p.x);
		atom.setY(p.y);
		atom.setZ(p.z);
	}
741636
private String render(boolean compact) {
    StringBuilder buf = new StringBuilder();
    render(buf, LANGUAGE, UNDEF_LANGUAGE, compact);
    render(buf, SCRIPT, UNDEF_SCRIPT, compact);
    render(buf, TERRITORY, UNDEF_TERRITORY, compact);
    render(buf, VARIANT, UNDEF_VARIANT, compact);
    return buf.toString();
  }
555181
public String renderToString(String templateName, Map<String, Object> model) {
        if (templateEngine == null) {
            throw new PippoRuntimeException("You must set a template engine in your application");
        }

        // merge the model passed with the locals data
        model.putAll(getLocals());

        // add session (if exists) to model
        Session session = Session.get();
        if (session != null) {
            model.put("session", session);
        }

        // render the template using the merged model
        StringWriter stringWriter = new StringWriter();
        templateEngine.renderResource(templateName, model, stringWriter);

        return stringWriter.toString();
    }
703361
public void setModelByText(String model) {
        try {
            InputStream is = new ByteArrayInputStream(model.getBytes());
            this.model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions());
            this.setStateMachine(this.model);
        } catch (IOException | SAXException | ModelException e) {
            e.printStackTrace();
        }
    }
564510
static Vector2d newUnitVector(final IAtom atom, final IBond bond) {
        return newUnitVector(atom.getPoint2d(), bond.getOther(atom).getPoint2d());
    }
1276166
@Override
    public void addAtom(IAtom atom) {
        if (contains(atom)) {
            return;
        }

        if (atomCount + 1 >= atoms.length) {
            growAtomArray();
        }
        atom.addListener(this);
        atoms[atomCount] = atom;
        atomCount++;
        notifyChanged();
    }
43622
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WPanel panel = (WPanel) component;
		XmlStringBuilder xml = renderContext.getWriter();
		ColumnLayout layout = (ColumnLayout) panel.getLayout();
		int childCount = panel.getChildCount();
		Size hgap = layout.getHorizontalGap();
		String hgapString = hgap == null ? null : hgap.toString();
		Size vgap = layout.getVerticalGap();
		String vgapString = vgap == null ? null : vgap.toString();
		int cols = layout.getColumnCount();

		xml.appendTagOpen("ui:columnlayout");
		xml.appendOptionalAttribute("hgap", hgapString);
		xml.appendOptionalAttribute("vgap", vgapString);
		xml.appendClose();

		// Column Definitions
		for (int col = 0; col < cols; col++) {
			xml.appendTagOpen("ui:column");
			int width = layout.getColumnWidth(col);
			xml.appendOptionalAttribute("width", width > 0, width);

			switch (layout.getColumnAlignment(col)) {
				case LEFT:
					// left is assumed if omitted
					break;

				case RIGHT:
					xml.appendAttribute("align", "right");
					break;

				case CENTER:
					xml.appendAttribute("align", "center");
					break;

				default:
					throw new IllegalArgumentException("Invalid alignment: " + layout.
							getColumnAlignment(col));
			}

			xml.appendEnd();
		}

		for (int i = 0; i < childCount; i++) {
			xml.appendTag("ui:cell");
			WComponent child = panel.getChildAt(i);
			child.paint(renderContext);
			xml.appendEndTag("ui:cell");
		}

		xml.appendEndTag("ui:columnlayout");
	}
79797
public static <T> TextField<T> newTextField(final String id, final IModel<T> model)
	{
		final TextField<T> textField = new TextField<>(id, model);
		textField.setOutputMarkupId(true);
		return textField;
	}