• Introduction
    • Installation
      • Conda
      • UV
      • Integration Testing
    • Available Scripts
    • Outline of Recipes
  • Image Manipulation
    • Adding Logo to PNG Image
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
    • 🔄 Depicting Molecule in JPG
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • See also in OEChem manual
      • See also in OEDepict manual
    • 🆕 Depicting Molecule in Jupyter Notebook
      • Problem
      • Difficulty level
      • Download
  • 2D Depiction
    • Generating Transparent PNG
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
      • Discussion
      • See also in OEDepict TK manual
    • Depicting Polar Hydrogens
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Tripos Atom Types
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
      • Discussion
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Molecule with Various Styles
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
        • Default
        • Aromaticity Style
        • Atom Color Style
        • Super Atom Style
        • Atom Stereo Style
        • Bond Stereo Style
        • Title Style
        • Border Style
        • Display Atom Index
        • Display Bond Index
        • Display Atom Property
        • Display Bond Property
        • Hover Atom Property
        • Hover Bond Property
        • Toggle Atom Property
        • Toggle Bond Property
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Atom Contributions of XLogP
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage (xlogp2img)
      • Discussion
      • Usage (xlogp2pdf)
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in MolProp TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Fragment Contributions of XLogP
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage (fragxlogp2img)
      • Discussion
      • Usage (fragxlogp2pdf)
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in MolProp TK manual
      • See also in Quacpac TK manual
      • See also in OEMedChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Atom Properties
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Discussion
        • Atom Partial Charge
        • Atom XLogP Contribution
        • Usage
        • Usage (partial charge)
        • Usage (XLogP)
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Molecule Similarity Based on Fingerprints
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage (simcalc2img)
      • Discussion
      • Usage (simcalc2pdf)
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Topological Polar Surface Area
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Discussion
      • Usage (psa2img)
      • Usage (psa2pdf)
      • See also in OEChem TK manual
      • See also in MolProp TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Activities of Molecules
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
        • Usage
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Depicting Reaction Components
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Library Generation
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting CSV or SDF in PDF
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting CSV or SDF in HTML
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting CSV or SDF in XLSX (Excel)
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting CSV or SDF in PPTX (PowerPoint)
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • See also
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Highlighting Fragments
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Discussion
      • Usage (frags2img)
      • Usage (frags2pdf)
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEMedChem TK manual
      • See also in OEDepict TK manual
      • See also
    • Depicting Fragment Combinations
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEMedChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • 🆕 Depict SMILES in Interactive Web Application
      • Problem
      • Ingredients
      • Difficulty Level
      • Source Code
      • Usage
      • See also in OEDepict TK manual
    • Depicting Multiple Matches
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Molecular Graph Symmetry
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
        • Usage
      • Discussion
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
    • Depicting Molecular Properties
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • See also in OEChem TK manual
      • See also in MolProp TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
  • Visualizing 3D Information
    • Visualizing Torsional Angle Distribution
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
        • Visualizing Torsion Flexibility
        • Visualizing Torsional Angle Distribution with Reference
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • 🆕 Visualizing the Variability in Torsional Angle Sampling
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Molecular Dipole Moment
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Electron Density
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
      • See also
    • Visualizing Protein-Ligand B-factor
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Protein-Ligand B-factor Map
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Protein-Ligand B-factor Heat Map
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • 🔄 Visualizing Protein-Ligand Interactions
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
        • complex2img
        • 🚧 complexes2pdf
      • Discussion
        • Interaction perception
        • Interaction depiction
        • Hydrogen position optimization
        • 🚧 Custom Ligand Alignment
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in Spruce TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • 🔄 Visualizing Protein-Ligand Contacts
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in Spruce TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Protein-Ligand Unpaired Interactions
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
        • Interaction Perception
        • Unpaired Interaction Depiction
        • Hydrogen Position Optimization
        • Unpaired Map vs Active Site Interaction Map
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Protein-Ligand Maps
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Visualizing Shape and Color Overlap
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
      • See also in Shape TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
  • Plotting (not the evil kind)
    • 🔄 Ramachandran Plot
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • See also
      • See also in OEChem TK manual
      • See also in OEDepict TK manual
      • See also in GraphemeTM TK manual
    • Drawing ROC Curve
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in matplotlib documentation
      • See also in sklearn documentation
      • See also
    • Plotting ROC Curves of Fingerprint Similarity
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • Related Python Cookbook Recipes
      • See also in numpy documentation
      • See also in sklearn documentation
      • See also in matplotlib documentation
      • See also in GraphSim TK manual
    • Drawing Fingerprint Score Histogram
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
        • Performance
      • Related Python Cookbook Recipes
      • See also in GraphSim TK manual
      • See also in matplotlib documentation
  • Cheminformatics
    • Identifying Acceptor and Donor Atoms
      • Ingredients
      • Difficulty Level
      • Solution
      • Discussion
      • See also in OEChem TK manual
      • See also in OEMolProp TK manual
      • See also
    • Manipulating Large Molecule Files
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
        • Creating Molecule Database Index File
        • Counting Molecules
        • Output Molecule Titles
        • Extracting Molecules by Title
        • Extracting Random Set of Molecules
        • Splitting Molecule Database
        • Sorting Molecules
      • Discussion
      • See also in Python documentation
      • See also in OEChem TK manual
      • See also in OEMedChem TK manual
    • Rapid Similarity Searching of Large Molecule Files
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
        • Generating Fingerprints
      • Usage (makefastfp)
        • Searching Fingerprints
      • Usage (searchfastfp)
      • Discussion
        • Performance of fingerprint generation
        • Fingerprint search options
        • Performance of fingerprint search
        • Memory-Mapped vs In-Memory Search
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
    • Enumerating Fragment Combinations
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also in Python documentation
      • See also in OEChem TK manual
      • See also in OEMedChem TK manual
      • See also
    • Finding Core Fragment of a Molecule Series
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Discussion
      • Usage
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
      • See also
    • 🔄 Ring Perception
      • Problem
      • Ingredients
      • Difficulty level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
        • Identifying Spiro Atoms of a Molecule
        • Identifying Macro-cycle Atoms of a Molecule
        • Identifying Ring Systems of a Molecule
        • Identifying Aromatic Ring Systems of a Molecule
        • Identifying Atom in Certain Ring Size
        • Identifying Atom in Certain Aromatic Ring Size
        • Identifying Atoms’ Smallest Ring Size
      • See also in OEChem TK manual
    • Enumerating Atom Substitutions
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Discussion
      • See also in Python documentation
      • See also in OEChem TK manual
    • 🔄 Accessing Interaction Hint Information
      • Ingredients
      • Difficulty Level
      • Solution
        • Perceiving Interaction Hints
        • Accessing Interactions
        • Accessing Interaction Atoms
        • Retrieving Interacting Residues
        • Accessing Calculated Interaction Hint Geometries
        • Serializing Interaction
      • Discussion
        • Overview of OEChem TK Interaction API
        • Atom predicates
        • Interaction predicates
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Print Protein-Ligand Interactions to Console
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Discussion
      • Usage
        • Input Ligand-Protein Complex
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Print the Summary of Protein-Ligand Interactions for a Set of Molecules
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Discussion
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Serialize Protein-Ligand Interactions
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
        • Serialization
        • Deserialization
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
  • 🆕 Peptide Informatics
    • 🆕 Theory
      • Monomers
        • Monomers with Peptide Polymer Type
        • Monomers with Chem Polymer Type
        • Monomers with Unspecified Stereochemistry
        • Defining Monomer Connection Points
      • OEChem TK Built-in Monomer Sets
      • HELM
      • HELM Parsing
        • Embedded SMILES
      • Helm Generation
        • Tautomer Handling
        • Handling Charged Molecules
        • Handling Molecules with Unspecified Stereochemistry
      • Peptide Cyclization and Cross-links
    • 🆕 Generating Custom Monomer Set
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Discussion
      • Usage
    • 🆕 Convert Monomers to OpenEye JSON Format
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
      • See also in OEChem TK manual
    • 🆕 Substructure Search in Monomer Set
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
      • See also in OEChem TK manual
    • 🆕 Similarity Search in Monomer Set
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Discussion
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
    • 🆕 Depict Monomer
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • See also in OEChem TK manual
      • See also in OEGrapheme TK manual
    • 🆕 Depict Peptide
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
        • Peptide Input
        • Depiction Options
        • Monomer Set Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in OEGrapheme TK manual
    • 🆕 Convert HELM to SMILES
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
        • Monomer Set Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Convert SMILES to HELM
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
        • Monomer Set Options
        • Helm Generation Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Convert HELM File to Molecule File
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
        • Monomer Set Options
        • Verbose Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Convert Molecule File to HELM File
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
        • Monomer Set Options
        • Verbose Options
        • Helm Generation Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Print Monomer Set Information to Console
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
      • See also in OEChem TK manual
    • 🆕 Plot Similarities in a Monomer Set
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Discussion
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
      • See also in GraphSim TK manual
      • See also in OEGrapheme TK manual
    • 🆕 Print Monomer Sequence of HELMS to Console
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Convert Peptides File to XLSX (Excel) with Monomer Sequence
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Usage
        • Monomer Set Options
        • Helm Generation Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Generate HELM in Interactive Web Application
      • Problem
      • Ingredients
      • Difficulty Level
      • Source Code
      • Usage
      • See also in OEChem TK manual
      • See also in OEGrapheme TK manual
    • 🆕 Generate Random Peptides
      • Problem
      • Ingredients
      • Difficulty Level
      • Solution
      • Download
      • Source Code
      • Usage
        • Output Options
        • Peptide Generation Options
        • Monomer Set Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
    • 🆕 Mutate Peptide
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
        • Output Options
        • Peptide Generation Options
        • Replacement Codes
        • Monomer Set Options
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
  • Molecular Modeling
    • Generating Canonical AM1-BCC Charges
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • See also in Omega TK manual
      • See also in Quacpac TK manual
  • Miscellaneous
    • Reordering CSV File
      • Problem
      • Ingredients
      • Difficulty Level
      • Download
      • Source Code
      • Solution
      • Usage
      • Related Python Cookbook Recipes
      • See also in OEChem TK manual
  • API References
    • Predicates
      • IsLipinskiAcceptor
        • IsLipinskiAcceptor
      • IsLipinskiDonor
        • IsLipinskiDonor
    • Functions
      • num_lipinsky_acceptors
        • num_lipinsky_acceptors()
      • num_lipinsky_donors
        • num_lipinsky_donors()
  • Just for Fun
    • Dalton
    • Picasso
    • OELove
    • Flag of New Mexico
    • OEHolidays
    • Depicting OpenEye Logo
    • Depicting molecule with shadow
    • OEAnime
    • Christmas Card
  • 📝 2026.1.0
  • OpenEye Glossary of Terms
  • Bibliography
    • Fingerprint Similarity Search
    • Interaction Perception
    • Drug-likeness
    • Maximum Common Substructure Search
    • Validating Protein-Ligand Structures
    • Peptide Informatics
    • Ramachandran Plot
    • Color References
  • Legal Notices
    • Copyright and Trademarks
    • Sample Code
    • Citation
      • Orion®
      • Orion Floes
      • Toolkits and Applications
      • Publications for Bibliographies
        • Orion
        • AFITT and FLYNN Applications
        • OEDocking Application and Toolkit
        • OMEGA Application and Toolkit
        • ROCS Application
      • OpenEye MMDS Web Service
    • Technology Licensing
    • GCC
      • GCC RUNTIME LIBRARY EXCEPTION
      • GNU GENERAL PUBLIC LICENSE
  • Index
Python Cookbook
  • All OpenEye Documentation »
  • Contents »
  • 🆕 Peptide Informatics »
  • 🆕 Print Monomer Sequence of HELMS to Console

🆕 Print Monomer Sequence of HELMS to Console

Problem

You want to inspect a helm file and display a monomer sequence of the PEPTIDE1 chain in the terminal.

See also

  • [Zhang-2012] publication

Ingredients

  • OEChem TK - cheminformatics toolkit

Difficulty Level

🌶️ 🌶️

Download

Download code

helms2console.py

See also Usage subsection.

Source Code

helms2console
#!/usr/bin/env python3
# (C) 2026 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.

"""Print monomer list of HELMs to console."""

import argparse
import json
import os
import pathlib
import sys
from typing import NewType

import rich.box
import rich.console
import rich.table
import rich.text
from openeye import oechem
from rich_argparse import HelpPreviewAction, RichHelpFormatter

__SCRIPT_NAME__ = pathlib.Path(__file__).absolute().stem
__SCRIPT_DESC__ = "Print monomers to console."
__SCRIPT_TOOLKITS__ = ["oechem"]
__SCRIPT_KEYWORDS__ = ["HELM", "peptide", "sequence", "peptide-informatics"]
__SCRIPT_CATEGORIES__ = ["peptide-informatics"]


def parse_options() -> argparse.Namespace:
    """Set up command line options."""
    parser = argparse.ArgumentParser(
        add_help=True,
        formatter_class=RichHelpFormatter,
        description="[yellow]" + __SCRIPT_DESC__ + "[/yellow]",
    )
    io_group = parser.add_argument_group("Input options")
    io_group.add_argument(
        "--helm",
        "--helm-file",
        metavar="HELM-FILE",
        type=str,
        required=True,
        help="input file of HELM string",
    )
    monomers_group = parser.add_argument_group("Monomer set options")
    _add_monomer_collection(monomers_group)

    parser.add_argument("--help-image", action=HelpPreviewAction)
    parser.add_argument(
        "--save-console-svg",
        default=False,
        action="store_true",
        help=f"run command and capture console output in {__SCRIPT_NAME__}.svg file",
    )
    return parser.parse_args()


MonomerSequence = NewType("MonomerSequence", list[str])


def main() -> int:
    """Print monomer list of HELMs to console."""
    args = parse_options()

    console = rich.console.Console(record=args.save_console_svg)
    monomers: oechem.OEMonomerSet = _get_monomer_collection(args)
    code_set = args.code_set or monomers.GetPrimaryCodeSet()

    helms_with_titles: list[tuple[str, str]] = _read_helms_with_title(args.helm)
    has_titles = any(title for _, title in helms_with_titles)
    console.print(
        f"{len(helms_with_titles)} HELMS read from {pathlib.Path(args.helm).name}!"
    )

    monomer_sequences_with_titles = _get_monomer_sequences(helms_with_titles)
    max_sequence_length = max(len(s) for s, _ in monomer_sequences_with_titles)
    monomer_color_dict: dict[str, str] = _get_monomer_colors(
        monomer_sequences_with_titles, monomers, code_set
    )

    table = rich.table.Table(
        title=f"[bold]Number of sequences: {len(monomer_sequences_with_titles)}[/bold]",
        box=rich.box.SIMPLE,
        collapse_padding=True,
        pad_edge=False,
    )
    table.add_column("idx", justify="right")
    for pos in range(1, max_sequence_length + 1):
        table.add_column(f"P{pos:02d}", justify="center")
    if has_titles:
        table.add_column("Title", justify="left")

    for idx, (sequence, title) in enumerate(monomer_sequences_with_titles, start=1):
        sequence_repr: list[rich.text.Text] = [
            rich.text.Text(str(idx)),
            *_get_colored_sequence(sequence, monomer_color_dict),
            rich.text.Text(title),
        ]
        table.add_row(*sequence_repr)

    console.print(table)

    if args.save_console_svg:
        console.save_svg(f"{__SCRIPT_NAME__}.svg", title="output")
    return os.EX_OK


def _read_helms_with_title(helm_filename: str) -> list[tuple[str, str]]:
    # script will terminate if reading HELM string from file fails
    helm_filepath = pathlib.Path(helm_filename)
    if not helm_filepath.exists():
        oechem.OEThrow.Fatal(f"{helm_filename} file does not exist!")
    if helm_filepath.suffix.lower() != ".helm":
        oechem.OEThrow.Fatal("Invalid file extension expected .helm!")

    helms: list[tuple[str, str]] = []
    try:
        with helm_filepath.open() as helm_file:
            for line in helm_file:
                helm, _, title = line.rstrip().partition(" ")
                helms.append((helm, title))
    except OSError:
        oechem.OEThrow.Fatal(f"Can not open {helm_filename} input file!")

    if len(helms) == 0:
        oechem.OEThrow.Fatal(f"No helm string read from {helm_filename}!")
        return []
    return helms


def _get_monomer_colors(
    monomer_sequences_with_titles: list[tuple[MonomerSequence, str]],
    monomers: oechem.OEMonomerSet,
    code_set: str,
) -> dict[str, str]:
    unique_monomer_codes: set[str] = {
        c for s, _ in monomer_sequences_with_titles for c in s
    }

    monomer_colors: dict[str, str] = {}
    for code in unique_monomer_codes:
        if (monomer := monomers.GetMonomer(code_set, code)) is not None:
            color = _get_monomer_analog_color(monomer)
            monomer_colors[code] = color
    return monomer_colors


def _get_monomer_analog_color(monomer: oechem.OEMonomer) -> str:  # noqa: PLR0911
    if monomer.GetPolymerType() != oechem.OEPolymerType_Peptide:
        return "#000000"
    analog = oechem.OEGetStandardAnalog(monomer.GetCanonicalSmiles())
    if analog == oechem.OEResidueIndex_UNK:
        return "#AAAAAA"
    match analog:
        case oechem.OEResidueIndex_CYS | oechem.OEResidueIndex_MET:
            return "#e4e488"
        case (
            oechem.OEResidueIndex_ALA
            | oechem.OEResidueIndex_GLY
            | oechem.OEResidueIndex_ILE
            | oechem.OEResidueIndex_LEU
            | oechem.OEResidueIndex_PRO
            | oechem.OEResidueIndex_VAL
        ):
            return "#c09071"
        case (
            oechem.OEResidueIndex_PHE
            | oechem.OEResidueIndex_TRP
            | oechem.OEResidueIndex_TYR
        ):
            return "#5faf5f"
        case oechem.OEResidueIndex_ASP | oechem.OEResidueIndex_GLU:
            return "#e0ac70"
        case (
            oechem.OEResidueIndex_ARG
            | oechem.OEResidueIndex_HIS
            | oechem.OEResidueIndex_LYS
        ):
            return "#85b4e6"
        case oechem.OEResidueIndex_SER | oechem.OEResidueIndex_THR:
            return "#ff8787"
        case oechem.OEResidueIndex_ASN | oechem.OEResidueIndex_GLN:
            return "#5493EA"
    return "#AAAAAA"


def _get_monomer_sequences(
    helms_with_title: list[tuple[str, str]],
) -> list[tuple[MonomerSequence, str]]:
    monomer_sequences: list[tuple[MonomerSequence, str]] = []

    chain_name = "PEPTIDE1"
    for helm, title in helms_with_title:
        monomer_codes = oechem.OEGetHelmMonomerCodes(helm, chain_name)
        if len(monomer_codes) > 0:
            monomer_sequences.append((monomer_codes, title))

    return monomer_sequences


def _get_colored_sequence(
    monomer_sequence: MonomerSequence, monomer_color_dict: dict[str, str]
) -> list[rich.text.Text]:
    colored_sequence: list[rich.text.Text] = []
    for code in monomer_sequence:
        bg_color = monomer_color_dict.get(code, "white")
        style = rich.text.Style(color="black", bgcolor=bg_color, bold=True)
        colored_sequence.append(rich.text.Text(code, style, justify="center"))
    return colored_sequence


class MonomerSetParameter:  # noqa: PLW1641
    """Utility class to handle both built-in and user defined monomer sets."""

    def __init__(self) -> None:  # noqa: D107
        self._monomer_sets = ["Standard", "OpenEye", "JSON-FILENAME"]

    def __repr__(self) -> str:  # noqa: D105
        return ",".join(self._monomer_sets)

    def __eq__(self, param: object) -> bool:  # noqa: D105
        if not isinstance(param, str):
            return False
        if param in ["Standard", "OpenEye"]:
            return True

        console = rich.console.Console()
        monomer_set_filepath = pathlib.Path(param)
        if (
            not monomer_set_filepath.exists()
            or monomer_set_filepath.suffix.lower() != ".json"
        ):
            console.print(f"[red]Invalid monomer set file '{param}' ![/red]")
            return False
        try:
            with monomer_set_filepath.open("r") as json_file:
                json.load(json_file)
        except json.JSONDecodeError as e:
            console.print(f"[red]Invalid monomer set file '{param}' ![/red]")
            console.print(f"[red]Error decoding JSON: {e} ![/red]")
            return False
        return True


def _add_monomer_collection(arg_group: argparse._ArgumentGroup) -> None:
    arg_group.add_argument(
        "-m",
        "--monomers",
        type=str,
        default="Standard",
        choices=[MonomerSetParameter()],
        help="built-in monomer-set type or json file of monomers",
    )
    arg_group.add_argument(
        "--code-set",
        type=str,
        metavar="CODE-SET",
        required=False,
        default=None,
        help="code-set, if not specified primary code-set is used",
    )


def _get_monomer_collection(args: argparse.Namespace) -> oechem.OEMonomerSet:
    monomers = oechem.OEMonomerSet()
    match args.monomers:
        case "Standard":
            oechem.OELoadStandardMonomerSet(monomers)
        case "OpenEye":
            oechem.OELoadOpenEyeMonomerSet(monomers)
        case _:
            oechem.OEReadMonomerSet(monomers, args.monomers)
    return monomers


setattr(main, "__SCRIPT_NAME__", __SCRIPT_NAME__)
setattr(main, "__SCRIPT_DESC__", __SCRIPT_DESC__)
setattr(main, "__SCRIPT_TOOLKITS__", __SCRIPT_TOOLKITS__)
setattr(main, "__SCRIPT_KEYWORDS__", __SCRIPT_KEYWORDS__)
setattr(main, "__SCRIPT_CATEGORIES__", __SCRIPT_CATEGORIES__)

if __name__ == "__main__":
    sys.exit(main())

Solution

The helms2console will not fully validate or parse the input HELM strings; rather, it uses the OEGetHelmMonomerCodes function to extract the monomers of the PEPTIDE1 component of each input HELM.

Usage

See Download section to download the script.

> helms2console --help
../_images/helms2console-help.svg

By default, the helms2console script uses OEChem TK’s built-in Standard monomer set to try to assign colors to the monomers.

> helms2console --helm test.helm

The output for the test.helm input file:

../_images/helms2console-01-stdout.svg
--monomers OpenEye
--monomers JSON-MONOMER-FILE
> helms2console --helm test-custom.helm --monomers custom-monomers.json

The output for the test-custom.helm input file with test-custom.helm custom monomer set:

../_images/helms2console-02-stdout.svg

Related Python Cookbook Recipes

  • 🆕 Convert Molecule File to HELM File

See also in OEChem TK manual

  • OEGetHelmMonomerCodes function

  • OEMonomer class

  • OEMonomerSet class

  • OEReadMonomerSet, OELoadStandardMonomerSet, and OELoadOpenEyeMonomerSet functions

Previous Next

© Copyright 2026, Cadence Design Systems, Inc. Last updated on Aug 11, 2026.