Im 1st year mbbs student in exam imp questions list i saw one question is 4 mark question is classification of lipids give a answer of this question easy to understand English language,when I read this question answer I understand easily, give answer this type when I read this question answer first time so much answer I understand easily in first time and when i write this in exam my sir will give me full out of full marks and easy to read and understand,answer give as 1 st year mbbs [ Biochemistry ]and easy to understand and write Thank you

Reading File
Finding Sources
Finding Sources
Finding Sources
Reading File
Finding Sources
I have enough content from the textbook. Now let me write a clear, exam-ready answer for a 1st year MBBS student.

Classification of Lipids

[ 1st Year MBBS - Biochemistry | 4 Marks ]

Definition

Lipids are organic compounds that are insoluble in water but soluble in organic solvents (like ether, chloroform, benzene). They contain carbon, hydrogen, and oxygen (some also contain nitrogen, phosphorus, sulfur).

Classification of Lipids

Lipids are broadly classified into 3 main groups:

1. Simple Lipids

"Simple = Fatty acid + Alcohol only"
These are esters of fatty acids with alcohols. No extra groups attached.
TypeDescriptionExample
Fats (Triglycerides)Fatty acid + Glycerol (3 fatty acids)Butter, body fat
WaxesFatty acid + Long-chain alcoholBeeswax, earwax

2. Compound Lipids (Complex Lipids)

"Compound = Simple lipid + Extra group"
These have a fatty acid + alcohol + one more extra group added.
TypeExtra Group AddedExample
PhospholipidsPhosphate + Nitrogen baseLecithin (in cell membranes)
GlycolipidsCarbohydrate (sugar)Cerebrosides (in brain/nerve tissue)
LipoproteinsProteinHDL, LDL (transport lipids in blood)
SulfolipidsSulfate groupPresent in brain
AminolipidsAmino groupPresent in tissues

3. Derived Lipids

"Derived = Products obtained FROM simple or compound lipids"
These are substances obtained when simple or compound lipids are broken down (hydrolyzed).
TypeExample
Fatty acidsPalmitic acid, Stearic acid
SterolsCholesterol, Ergosterol
GlycerolBackbone of triglycerides
Fat-soluble vitaminsVitamin A, D, E, K
Steroid hormonesCortisol, Testosterone, Estrogen
Bile acidsCholic acid (help in fat digestion)
ProstaglandinsInvolved in inflammation

Quick Memory Trick

"S - C - D"
  • S = Simple (fats + waxes)
  • C = Compound (phospholipids, glycolipids, lipoproteins)
  • D = Derived (fatty acids, sterols, vitamins, hormones)

Summary Table (Write this in exam for full marks!)

ClassWhat it isKey Example
Simple LipidsFA + AlcoholTriglycerides, Waxes
Compound LipidsFA + Alcohol + Extra groupPhospholipids, Glycolipids
Derived LipidsBreakdown products of aboveCholesterol, Fatty acids, Vitamins A/D/E/K

Important Points to Remember

  • Phospholipids are the most important compound lipid - they form the cell membrane (lipid bilayer).
  • Cholesterol is the most important sterol - it is the parent molecule for steroid hormones, bile acids, and Vitamin D.
  • Triglycerides are the main storage form of energy in the body.
  • Lipoproteins (HDL, LDL, VLDL) carry lipids in the blood because lipids alone cannot dissolve in blood.

Writing Tip for Exam: Start with the definition, then write the 3 main classes with a table each, end with important clinical points. This structure will impress your examiner and get you full 4/4 marks. Good luck!

Create a study guide PDF with lipid classification diagrams

Reading File
Running Command

ls /home/daytona/workspace/ 2>/dev/null || echo "workspace empty or not found"

Running Command

mkdir -p /home/daytona/workspace/lipids-study-guide && python3 -c "import report…

Writing File

~/lipids-study-guide/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import cm, mm
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
    HRFlowable, KeepTogether
)
from reportlab.graphics.shapes import (
    Drawing, Rect, String, Line, Polygon, RoundRect, Group
)
from reportlab.graphics import renderPDF
from reportlab.graphics.shapes import Drawing, Rect, String, Line, Circle, RoundRect
from reportlab.lib.colors import (
    HexColor, white, black
)
import os

OUTPUT = "/home/daytona/workspace/lipids-study-guide/Lipid_Classification_Study_Guide.pdf"

# ── Colour palette ──────────────────────────────────────────────────────────
C_BLUE_DARK  = HexColor("#1A3C6E")   # headings / title bar
C_BLUE_MID   = HexColor("#2E6FD8")   # subheadings
C_BLUE_LIGHT = HexColor("#D6E6FF")   # row shading
C_GREEN      = HexColor("#1B7A3E")   # Simple lipids
C_GREEN_L    = HexColor("#D4F0E0")
C_PURPLE     = HexColor("#6A1B9A")   # Compound lipids
C_PURPLE_L   = HexColor("#EDE0F7")
C_ORANGE     = HexColor("#B85C00")   # Derived lipids
C_ORANGE_L   = HexColor("#FDEBD0")
C_YELLOW     = HexColor("#FFF9C4")   # highlight
C_GRAY_LIGHT = HexColor("#F5F5F5")
C_GRAY_MID   = HexColor("#CCCCCC")
C_RED        = HexColor("#C0392B")

# ── Document ─────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=1.5*cm, rightMargin=1.5*cm,
    topMargin=1.5*cm, bottomMargin=1.5*cm
)
W, H = A4
TW = W - 3*cm   # text width

styles = getSampleStyleSheet()

# Custom paragraph styles
def PS(name, **kw):
    return ParagraphStyle(name, **kw)

title_style = PS("Title2",
    fontName="Helvetica-Bold", fontSize=22,
    textColor=white, alignment=TA_CENTER, spaceAfter=4)

subtitle_style = PS("Subtitle",
    fontName="Helvetica", fontSize=11,
    textColor=HexColor("#BBDEFB"), alignment=TA_CENTER)

h1 = PS("H1",
    fontName="Helvetica-Bold", fontSize=14,
    textColor=white, alignment=TA_CENTER, spaceAfter=2)

h2 = PS("H2",
    fontName="Helvetica-Bold", fontSize=12,
    textColor=C_BLUE_DARK, spaceBefore=8, spaceAfter=4)

h3_green = PS("H3G",
    fontName="Helvetica-Bold", fontSize=11,
    textColor=C_GREEN, spaceBefore=6, spaceAfter=2)

h3_purple = PS("H3P",
    fontName="Helvetica-Bold", fontSize=11,
    textColor=C_PURPLE, spaceBefore=6, spaceAfter=2)

h3_orange = PS("H3O",
    fontName="Helvetica-Bold", fontSize=11,
    textColor=C_ORANGE, spaceBefore=6, spaceAfter=2)

body = PS("Body",
    fontName="Helvetica", fontSize=9.5,
    textColor=HexColor("#212121"), leading=14, spaceAfter=3)

body_bold = PS("BodyBold",
    fontName="Helvetica-Bold", fontSize=9.5,
    textColor=HexColor("#212121"), leading=14)

small = PS("Small",
    fontName="Helvetica", fontSize=8.5,
    textColor=HexColor("#444444"), leading=12)

tip = PS("Tip",
    fontName="Helvetica-BoldOblique", fontSize=9,
    textColor=C_BLUE_DARK, leading=13)

memory = PS("Memory",
    fontName="Helvetica-Bold", fontSize=10,
    textColor=C_RED, alignment=TA_CENTER, spaceAfter=2)

# ─────────────────────────────────────────────────────────────────────────────
# Helper: coloured banner paragraph
# ─────────────────────────────────────────────────────────────────────────────
def banner(text, style, bg, pad=6, radius=6):
    tbl = Table([[Paragraph(text, style)]], colWidths=[TW])
    tbl.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), bg),
        ("ROUNDEDCORNERS", [radius]*4),
        ("TOPPADDING",    (0,0), (-1,-1), pad),
        ("BOTTOMPADDING", (0,0), (-1,-1), pad),
        ("LEFTPADDING",   (0,0), (-1,-1), 10),
        ("RIGHTPADDING",  (0,0), (-1,-1), 10),
    ]))
    return tbl

# ─────────────────────────────────────────────────────────────────────────────
# Helper: section box
# ─────────────────────────────────────────────────────────────────────────────
def section_box(content_rows, header_text, header_bg, stripe_bg):
    """content_rows: list of [left_cell, right_cell] pairs"""
    data = [[Paragraph(f"<b>{header_text}</b>",
                       PS("SH", fontName="Helvetica-Bold", fontSize=10,
                          textColor=white, alignment=TA_LEFT)),
             ""]]
    data += content_rows
    col_w = [TW*0.38, TW*0.62]
    tbl = Table(data, colWidths=col_w)
    style_cmds = [
        ("SPAN",          (0,0), (1,0)),
        ("BACKGROUND",    (0,0), (1,0), header_bg),
        ("TEXTCOLOR",     (0,0), (1,0), white),
        ("FONTNAME",      (0,0), (1,0), "Helvetica-Bold"),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
        ("RIGHTPADDING",  (0,0), (-1,-1), 8),
        ("GRID",          (0,1), (-1,-1), 0.4, C_GRAY_MID),
        ("LINEBELOW",     (0,0), (1,0), 1, white),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]
    for i in range(1, len(data)):
        bg = stripe_bg if i % 2 == 0 else white
        style_cmds.append(("BACKGROUND", (0,i), (1,i), bg))
    tbl.setStyle(TableStyle(style_cmds))
    return tbl

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 1 – Tree / Mind-map of Lipid Classification
# ─────────────────────────────────────────────────────────────────────────────
def make_tree_diagram():
    dw, dh = TW, 210
    d = Drawing(dw, dh)

    cx = dw / 2  # centre x
    root_y = dh - 30
    root_w, root_h = 160, 30

    def box(x, y, w, h, fill, text, font_size=9, text_color=white, radius=5):
        r = RoundRect(x - w/2, y - h/2, w, h, radius, fillColor=fill,
                      strokeColor=HexColor("#555555"), strokeWidth=0.5)
        d.add(r)
        s = String(x, y - font_size*0.4, text,
                   fontName="Helvetica-Bold", fontSize=font_size,
                   fillColor=text_color, textAnchor="middle")
        d.add(s)

    def line(x1, y1, x2, y2, color=HexColor("#888888"), w=1):
        d.add(Line(x1, y1, x2, y2, strokeColor=color, strokeWidth=w))

    # Root
    box(cx, root_y, root_w, root_h, C_BLUE_DARK, "LIPIDS", font_size=13)

    # 3 branches
    branch_y = root_y - 70
    branches = [
        (cx - 195, branch_y, 110, 28, C_GREEN,  "1. SIMPLE"),
        (cx,       branch_y, 130, 28, C_PURPLE, "2. COMPOUND"),
        (cx + 195, branch_y, 110, 28, C_ORANGE, "3. DERIVED"),
    ]
    for bx, by, bw, bh, bc, bt in branches:
        line(cx, root_y - root_h//2, bx, by + bh//2, color=bc, w=1.5)
        box(bx, by, bw, bh, bc, bt, font_size=10)

    # Leaves
    leaves = [
        # Simple lipids
        (cx - 245, branch_y - 55, 95, 22, C_GREEN_L,   "Fats (Triglycerides)", C_GREEN),
        (cx - 145, branch_y - 55, 95, 22, C_GREEN_L,   "Waxes",               C_GREEN),
        # Compound lipids
        (cx - 75,  branch_y - 55, 90, 22, C_PURPLE_L,  "Phospholipids",       C_PURPLE),
        (cx + 5,   branch_y - 55, 85, 22, C_PURPLE_L,  "Glycolipids",         C_PURPLE),
        (cx + 85,  branch_y - 55, 90, 22, C_PURPLE_L,  "Lipoproteins",        C_PURPLE),
        # Derived
        (cx + 145, branch_y - 55, 88, 22, C_ORANGE_L,  "Fatty Acids",         C_ORANGE),
        (cx + 238, branch_y - 55, 88, 22, C_ORANGE_L,  "Sterols",             C_ORANGE),
    ]
    # parent connections
    parent_map = [
        (0, cx-195), (1, cx-195),
        (2, cx), (3, cx), (4, cx),
        (5, cx+195), (6, cx+195),
    ]
    for idx, (li, bx_parent) in enumerate(parent_map):
        lx, ly, lw, lh, lc, lt, tc = leaves[idx]
        line(bx_parent, branch_y - 28//2, lx, ly + lh//2, color=lc, w=1)
        r = RoundRect(lx - lw/2, ly - lh/2, lw, lh, 4,
                      fillColor=lc, strokeColor=HexColor("#AAAAAA"), strokeWidth=0.4)
        d.add(r)
        s = String(lx, ly - 3.5, lt,
                   fontName="Helvetica", fontSize=7.5,
                   fillColor=tc, textAnchor="middle")
        d.add(s)

    # Extra leaves row (more derived items)
    extra = [
        (cx + 145, branch_y - 88, 88, 18, C_ORANGE_L, "Vitamins A,D,E,K", C_ORANGE),
        (cx + 238, branch_y - 88, 88, 18, C_ORANGE_L, "Steroid Hormones",  C_ORANGE),
    ]
    for ex, ey, ew, eh, ec, et, etc_ in extra:
        line(cx+195, branch_y - 55 - 22//2, ex, ey + eh//2, color=C_ORANGE, w=0.8)
        r = RoundRect(ex - ew/2, ey - eh/2, ew, eh, 4,
                      fillColor=ec, strokeColor=HexColor("#AAAAAA"), strokeWidth=0.3)
        d.add(r)
        s = String(ex, ey - 3, et,
                   fontName="Helvetica", fontSize=7,
                   fillColor=etc_, textAnchor="middle")
        d.add(s)

    return d

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 2 – Phospholipid structure diagram
# ─────────────────────────────────────────────────────────────────────────────
def make_phospholipid_diagram():
    dw, dh = TW * 0.55, 140
    d = Drawing(dw, dh)

    # Head group (hydrophilic)
    head_y = dh - 35
    head_r = RoundRect(dw/2 - 40, head_y - 20, 80, 40, 8,
                       fillColor=HexColor("#AED6F1"), strokeColor=C_BLUE_MID, strokeWidth=1)
    d.add(head_r)
    d.add(String(dw/2, head_y - 5, "POLAR HEAD",
                 fontName="Helvetica-Bold", fontSize=8,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))
    d.add(String(dw/2, head_y - 16, "(Phosphate + Choline)",
                 fontName="Helvetica", fontSize=7,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))

    # Glycerol backbone
    bb_y = head_y - 45
    d.add(RoundRect(dw/2 - 20, bb_y - 10, 40, 20, 4,
                    fillColor=HexColor("#F9E79F"), strokeColor=HexColor("#B7950B"), strokeWidth=1))
    d.add(String(dw/2, bb_y - 5, "Glycerol",
                 fontName="Helvetica-Bold", fontSize=7.5,
                 fillColor=HexColor("#7D6608"), textAnchor="middle"))

    # Connector lines
    d.add(Line(dw/2, head_y - 20, dw/2, bb_y + 10,
               strokeColor=C_BLUE_MID, strokeWidth=1.5))

    # Two fatty acid tails
    tail_y_top = bb_y - 10
    tail_h = 50
    for tx, label in [(dw/2 - 22, "Fatty Acid\n(tail 1)"), (dw/2 + 22, "Fatty Acid\n(tail 2)")]:
        d.add(Line(tx, tail_y_top, tx, tail_y_top - tail_h,
                   strokeColor=C_ORANGE, strokeWidth=2.5))
        for seg_y in range(int(tail_y_top - 5), int(tail_y_top - tail_h + 5), -8):
            pass  # just straight tails
        d.add(String(tx, tail_y_top - tail_h - 8, label.split("\n")[0],
                     fontName="Helvetica", fontSize=6.5,
                     fillColor=C_ORANGE, textAnchor="middle"))

    # Hydrophobic label
    d.add(String(dw/2, 8, "HYDROPHOBIC TAILS (Non-polar)",
                 fontName="Helvetica-BoldOblique", fontSize=7,
                 fillColor=C_ORANGE, textAnchor="middle"))
    d.add(String(dw/2, head_y + 12, "HYDROPHILIC HEAD (Polar)",
                 fontName="Helvetica-BoldOblique", fontSize=7,
                 fillColor=C_BLUE_MID, textAnchor="middle"))

    return d

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 3 – Triglyceride structure
# ─────────────────────────────────────────────────────────────────────────────
def make_triglyceride_diagram():
    dw, dh = TW * 0.45, 140
    d = Drawing(dw, dh)

    mid_x = dw / 2
    # Glycerol column
    gy = [dh - 30, dh - 60, dh - 90]
    for i, y in enumerate(gy):
        d.add(RoundRect(mid_x - 28, y - 12, 56, 24, 4,
                        fillColor=HexColor("#F9E79F"),
                        strokeColor=HexColor("#B7950B"), strokeWidth=0.8))
        d.add(String(mid_x, y - 4, f"C{i+1} — OH",
                     fontName="Helvetica-Bold", fontSize=8,
                     fillColor=HexColor("#7D6608"), textAnchor="middle"))
    # Backbone label
    d.add(String(mid_x, dh - 10, "GLYCEROL",
                 fontName="Helvetica-Bold", fontSize=8,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))

    # Fatty acid tails
    fa_x = mid_x + 80
    for i, y in enumerate(gy):
        d.add(Line(mid_x + 28, y, fa_x - 35, y,
                   strokeColor=HexColor("#888888"), strokeWidth=0.8))
        d.add(Line(fa_x - 35, y - 10, fa_x + 35, y - 10,
                   strokeColor=C_ORANGE, strokeWidth=2.5))
        d.add(String(fa_x, y - 10 - 8, f"Fatty Acid {i+1}",
                     fontName="Helvetica", fontSize=7,
                     fillColor=C_ORANGE, textAnchor="middle"))
        # ester bond label
        d.add(String(mid_x + 50, y + 3, "ester bond",
                     fontName="Helvetica-Oblique", fontSize=6,
                     fillColor=HexColor("#999999"), textAnchor="middle"))

    d.add(String(dw/2, 5, "TRIGLYCERIDE = Glycerol + 3 Fatty Acids",
                 fontName="Helvetica-Bold", fontSize=7.5,
                 fillColor=C_GREEN, textAnchor="middle"))
    return d


# ─────────────────────────────────────────────────────────────────────────────
# BUILD STORY
# ─────────────────────────────────────────────────────────────────────────────
story = []

# ── COVER BANNER ────────────────────────────────────────────────────────────
cover = Table(
    [[Paragraph("CLASSIFICATION OF LIPIDS", title_style)],
     [Paragraph("1st Year MBBS · Biochemistry · 4-Mark Study Guide", subtitle_style)]],
    colWidths=[TW]
)
cover.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), C_BLUE_DARK),
    ("TOPPADDING",    (0,0), (-1,-1), 12),
    ("BOTTOMPADDING", (0,0), (-1,-1), 12),
    ("LEFTPADDING",   (0,0), (-1,-1), 12),
    ("RIGHTPADDING",  (0,0), (-1,-1), 12),
    ("ROUNDEDCORNERS", [8]*4),
]))
story.append(cover)
story.append(Spacer(1, 10))

# ── DEFINITION ───────────────────────────────────────────────────────────────
story.append(banner("📌  DEFINITION", h1, C_BLUE_DARK))
story.append(Spacer(1, 4))
story.append(Paragraph(
    "<b>Lipids</b> are <b>organic biomolecules</b> that are <b>insoluble in water</b> but "
    "<b>soluble in organic solvents</b> (ether, chloroform, benzene). "
    "They contain <b>C, H, O</b> (some also contain N, P, S). "
    "They serve as energy stores, membrane components, and signalling molecules.",
    body))
story.append(Spacer(1, 8))

# ── MAIN CLASSIFICATION DIAGRAM (Tree) ──────────────────────────────────────
story.append(banner("🌳  CLASSIFICATION OVERVIEW — MIND MAP", h1, C_BLUE_MID))
story.append(Spacer(1, 6))
story.append(make_tree_diagram())
story.append(Spacer(1, 6))

# ── SIMPLE LIPIDS ────────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("1.  SIMPLE LIPIDS", h1, C_GREEN),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Esters of <b>fatty acids + alcohol ONLY</b>. "
        "No extra group attached.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Fats (Triglycerides)</b>", body_bold),
             Paragraph("3 Fatty acids + Glycerol. Main <b>energy storage</b> in body. "
                       "E.g., body fat, butter, ghee.", small)],
            [Paragraph("<b>Waxes</b>", body_bold),
             Paragraph("1 Fatty acid + Long-chain alcohol. Water-repellent. "
                       "E.g., Beeswax (Myricyl palmitate), Earwax, Lanolin (skin).", small)],
        ],
        "TYPE  ▸  SIMPLE LIPIDS", C_GREEN, C_GREEN_L
    ),
    Spacer(1, 6),
]))

# Triglyceride diagram
story.append(Paragraph("<b>Triglyceride Structure:</b>", h2))
story.append(make_triglyceride_diagram())
story.append(Spacer(1, 6))

# ── COMPOUND LIPIDS ──────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("2.  COMPOUND LIPIDS  (Complex Lipids)", h1, C_PURPLE),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Simple lipid + <b>one extra non-lipid group</b>.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Phospholipids</b>", body_bold),
             Paragraph("Fatty acid + Glycerol + <b>Phosphate + Nitrogen base</b>. "
                       "Form <b>cell membrane bilayer</b>. E.g., Lecithin (PC), Cephalin (PE), Sphingomyelin.", small)],
            [Paragraph("<b>Glycolipids</b>", body_bold),
             Paragraph("Fatty acid + Sphingosine + <b>Carbohydrate (sugar)</b>. "
                       "Found in <b>brain & nerve tissue</b>. E.g., Cerebrosides, Gangliosides.", small)],
            [Paragraph("<b>Lipoproteins</b>", body_bold),
             Paragraph("Lipid + <b>Protein</b>. Transport lipids in <b>blood</b>. "
                       "E.g., HDL, LDL, VLDL, Chylomicrons.", small)],
            [Paragraph("<b>Sulfolipids</b>", body_bold),
             Paragraph("Contain a <b>sulfate (–SO₄)</b> group. Found in brain tissue.", small)],
            [Paragraph("<b>Aminolipids</b>", body_bold),
             Paragraph("Contain an <b>amino (–NH₂)</b> group. Found in body tissues.", small)],
        ],
        "TYPE  ▸  COMPOUND LIPIDS", C_PURPLE, C_PURPLE_L
    ),
]))
story.append(Spacer(1, 6))

# Phospholipid diagram
story.append(Paragraph("<b>Phospholipid Structure (Amphipathic):</b>", h2))
diag_row = Table([[make_phospholipid_diagram(),
                   Paragraph(
                       "<b>Key Points:</b><br/>"
                       "• Has a <b>hydrophilic (water-loving) head</b> — faces outward<br/>"
                       "• Has <b>hydrophobic (water-fearing) tails</b> — face inward<br/>"
                       "• This amphipathic nature allows formation of the<br/>"
                       "  <b>lipid bilayer</b> — the basic structure of all cell membranes<br/>"
                       "• Lecithin (phosphatidylcholine) is the most abundant<br/>"
                       "  phospholipid in the body<br/>"
                       "• Dipalmitoyl lecithin = <b>lung surfactant</b> (prevents alveolar collapse)",
                       PS("Note", fontName="Helvetica", fontSize=8.5,
                          textColor=HexColor("#212121"), leading=13)
                   )]],
                  colWidths=[TW*0.45, TW*0.55])
diag_row.setStyle(TableStyle([
    ("VALIGN", (0,0), (-1,-1), "TOP"),
    ("LEFTPADDING", (0,0), (-1,-1), 4),
    ("BACKGROUND", (1,0), (1,0), C_PURPLE_L),
    ("TOPPADDING", (1,0), (1,0), 8),
    ("BOTTOMPADDING", (1,0), (1,0), 8),
]))
story.append(diag_row)
story.append(Spacer(1, 6))

# ── DERIVED LIPIDS ───────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("3.  DERIVED LIPIDS", h1, C_ORANGE),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Products obtained by <b>hydrolysis</b> of simple or compound lipids. "
        "They do NOT contain ester linkage.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Fatty Acids</b>", body_bold),
             Paragraph("E.g., Palmitic (C16:0), Stearic (C18:0), Oleic (C18:1 — unsaturated). "
                       "Basic building blocks of all lipids.", small)],
            [Paragraph("<b>Sterols</b>", body_bold),
             Paragraph("<b>Cholesterol</b> — most important sterol. Precursor for steroid hormones, "
                       "bile acids & Vitamin D. Plant: Phytosterols. Fungi: Ergosterol.", small)],
            [Paragraph("<b>Glycerol</b>", body_bold),
             Paragraph("3-carbon backbone of triglycerides. Released on fat hydrolysis.", small)],
            [Paragraph("<b>Fat-Soluble Vitamins</b>", body_bold),
             Paragraph("<b>A, D, E, K</b> — stored in adipose tissue & liver. "
                       "NOT excreted easily → risk of toxicity if excess.", small)],
            [Paragraph("<b>Steroid Hormones</b>", body_bold),
             Paragraph("Cortisol, Aldosterone (adrenal cortex); Testosterone, Estrogen, Progesterone "
                       "(gonads). All derived from <b>Cholesterol</b>.", small)],
            [Paragraph("<b>Bile Acids</b>", body_bold),
             Paragraph("Cholic acid, Chenodeoxycholic acid. Made in liver from cholesterol. "
                       "Help in <b>fat digestion & absorption</b> in intestine.", small)],
            [Paragraph("<b>Prostaglandins</b>", body_bold),
             Paragraph("20-carbon compounds derived from Arachidonic acid. "
                       "Involved in <b>inflammation, pain, fever</b>.", small)],
        ],
        "TYPE  ▸  DERIVED LIPIDS", C_ORANGE, C_ORANGE_L
    ),
    Spacer(1, 6),
]))

# ── SUMMARY TABLE ────────────────────────────────────────────────────────────
story.append(banner("📋  EXAM SUMMARY TABLE — Write This in Your Exam!", h1, C_BLUE_DARK))
story.append(Spacer(1, 5))

sum_data = [
    [Paragraph("<b>Class</b>", PS("SH2", fontName="Helvetica-Bold", fontSize=9, textColor=white)),
     Paragraph("<b>Definition</b>", PS("SH2", fontName="Helvetica-Bold", fontSize=9, textColor=white)),
     Paragraph("<b>Examples</b>", PS("SH2", fontName="Helvetica-Bold", fontSize=9, textColor=white)),
     Paragraph("<b>Function</b>", PS("SH2", fontName="Helvetica-Bold", fontSize=9, textColor=white))],
    [Paragraph("<b>Simple</b>", PS("GH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_GREEN)),
     Paragraph("FA + Alcohol only", small),
     Paragraph("Triglycerides, Waxes", small),
     Paragraph("Energy storage, protection", small)],
    [Paragraph("<b>Compound</b>", PS("PH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_PURPLE)),
     Paragraph("Simple lipid + extra group", small),
     Paragraph("Phospholipids, Glycolipids, Lipoproteins", small),
     Paragraph("Cell membranes, lipid transport", small)],
    [Paragraph("<b>Derived</b>", PS("OH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_ORANGE)),
     Paragraph("Hydrolysis products", small),
     Paragraph("Cholesterol, Fatty acids, Vitamins A/D/E/K", small),
     Paragraph("Hormones, vitamins, bile, signalling", small)],
]
sum_tbl = Table(sum_data, colWidths=[TW*0.14, TW*0.25, TW*0.32, TW*0.29])
sum_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0), C_BLUE_DARK),
    ("BACKGROUND",    (0,1), (-1,1), C_GREEN_L),
    ("BACKGROUND",    (0,2), (-1,2), C_PURPLE_L),
    ("BACKGROUND",    (0,3), (-1,3), C_ORANGE_L),
    ("GRID",          (0,0), (-1,-1), 0.5, C_GRAY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(sum_tbl)
story.append(Spacer(1, 8))

# ── MEMORY TRICKS ─────────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("🧠  MEMORY TRICKS", h1, HexColor("#E74C3C")),
    Spacer(1, 5),
    Table(
        [[Paragraph(
            "<b>S – C – D</b><br/>"
            "<font color='#1B7A3E'><b>S</b></font> = Simple (Fats + Waxes)<br/>"
            "<font color='#6A1B9A'><b>C</b></font> = Compound (Phospho + Glyco + Lipoproteins)<br/>"
            "<font color='#B85C00'><b>D</b></font> = Derived (Cholesterol, FA, Vitamins, Hormones)",
            PS("Mem", fontName="Helvetica-Bold", fontSize=11,
               textColor=C_BLUE_DARK, leading=18)),
          Paragraph(
            "<b>For Compound Lipids:</b><br/>"
            "<font color='#6A1B9A'><b>P</b></font>lease <font color='#6A1B9A'><b>G</b></font>ive "
            "<font color='#6A1B9A'><b>L</b></font>ectures<br/>"
            "= <b>P</b>hosphol. · <b>G</b>lycolipids · <b>L</b>ipoproteins<br/><br/>"
            "<b>Fat-Soluble Vitamins: ADEK</b><br/>"
            "<i>\"A Dog Eats Kibble\"</i>",
            PS("Mem2", fontName="Helvetica", fontSize=10,
               textColor=C_BLUE_DARK, leading=16))]],
        colWidths=[TW*0.5, TW*0.5]
    ),
    Spacer(1, 5),
]))

# ── CLINICAL POINTS ───────────────────────────────────────────────────────────
story.append(Spacer(1, 4))
story.append(banner("⚕️  IMPORTANT CLINICAL POINTS (Impress Examiner!)", h1, HexColor("#1A7A1A")))
story.append(Spacer(1, 5))
clinical_data = [
    ["•", Paragraph("<b>Phospholipids</b> form the <b>lipid bilayer</b> of ALL cell membranes — amphipathic structure.", small)],
    ["•", Paragraph("<b>Cholesterol</b> is the parent molecule for: Steroid hormones, Bile acids, Vitamin D.", small)],
    ["•", Paragraph("<b>Triglycerides</b> = Main energy storage form. 1g fat → 9 kcal (more than carbs/proteins).", small)],
    ["•", Paragraph("<b>Lipoproteins</b> (HDL, LDL, VLDL, Chylomicrons) transport lipids in blood — lipids cannot dissolve alone in plasma.", small)],
    ["•", Paragraph("<b>Lung surfactant</b> = Dipalmitoyl phosphatidylcholine (DPPC) — prevents alveolar collapse on expiration.", small)],
    ["•", Paragraph("<b>Prostaglandins</b> derived from arachidonic acid — target of NSAIDs (aspirin, ibuprofen).", small)],
    ["•", Paragraph("<b>Fat-soluble vitamins A,D,E,K</b> → stored in liver/adipose tissue → toxicity possible if overdosed.", small)],
]
cli_tbl = Table(clinical_data, colWidths=[0.4*cm, TW - 0.4*cm])
cli_tbl.setStyle(TableStyle([
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ("TOPPADDING",    (0,0), (-1,-1), 3),
    ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING",   (0,0), (-1,-1), 4),
    ("RIGHTPADDING",  (0,0), (-1,-1), 4),
    ("ROWBACKGROUNDS", (0,0), (-1,-1),
     [HexColor("#F0FFF0"), HexColor("#FFFFFF")]),
]))
story.append(cli_tbl)
story.append(Spacer(1, 8))

# ── FOOTER ───────────────────────────────────────────────────────────────────
story.append(HRFlowable(width=TW, color=C_BLUE_DARK, thickness=1))
story.append(Spacer(1, 4))
story.append(Paragraph(
    "1st Year MBBS · Biochemistry · Classification of Lipids · Study Guide  |  Good Luck in Your Exams! 🎓",
    PS("Footer", fontName="Helvetica-Oblique", fontSize=8,
       textColor=HexColor("#888888"), alignment=TA_CENTER)
))

# ── BUILD ─────────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF saved to: {OUTPUT}")
Running Command

python3 /home/daytona/workspace/lipids-study-guide/generate_pdf.py 2>&1

Running Command

python3 -c "import reportlab.graphics.shapes as s; print(dir(s))" 2>&1 | tr ',' …

Running Command

python3 -c "import reportlab.graphics.shapes as s; shapes = [x for x in dir(s) i…

Writing File

~/lipids-study-guide/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import cm, mm
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
    HRFlowable, KeepTogether
)
from reportlab.graphics.shapes import Drawing, Rect, String, Line, Circle, Polygon, PolyLine
from reportlab.graphics import renderPDF
from reportlab.lib.colors import HexColor, white, black

OUTPUT = "/home/daytona/workspace/lipids-study-guide/Lipid_Classification_Study_Guide.pdf"

# ── Colour palette ──────────────────────────────────────────────────────────
C_BLUE_DARK  = HexColor("#1A3C6E")
C_BLUE_MID   = HexColor("#2E6FD8")
C_BLUE_LIGHT = HexColor("#D6E6FF")
C_GREEN      = HexColor("#1B7A3E")
C_GREEN_L    = HexColor("#D4F0E0")
C_PURPLE     = HexColor("#6A1B9A")
C_PURPLE_L   = HexColor("#EDE0F7")
C_ORANGE     = HexColor("#B85C00")
C_ORANGE_L   = HexColor("#FDEBD0")
C_RED        = HexColor("#C0392B")
C_GRAY_MID   = HexColor("#CCCCCC")
C_GRAY_LIGHT = HexColor("#F5F5F5")

# ── Document ─────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=1.5*cm, rightMargin=1.5*cm,
    topMargin=1.5*cm, bottomMargin=1.5*cm
)
W, H = A4
TW = W - 3*cm

styles = getSampleStyleSheet()

def PS(name, **kw):
    return ParagraphStyle(name, **kw)

title_style = PS("Title2",
    fontName="Helvetica-Bold", fontSize=22,
    textColor=white, alignment=TA_CENTER, spaceAfter=4)

subtitle_style = PS("Subtitle",
    fontName="Helvetica", fontSize=11,
    textColor=HexColor("#BBDEFB"), alignment=TA_CENTER)

h1 = PS("H1",
    fontName="Helvetica-Bold", fontSize=13,
    textColor=white, alignment=TA_CENTER, spaceAfter=2)

h2 = PS("H2",
    fontName="Helvetica-Bold", fontSize=12,
    textColor=C_BLUE_DARK, spaceBefore=8, spaceAfter=4)

body = PS("Body",
    fontName="Helvetica", fontSize=9.5,
    textColor=HexColor("#212121"), leading=14, spaceAfter=3)

body_bold = PS("BodyBold",
    fontName="Helvetica-Bold", fontSize=9.5,
    textColor=HexColor("#212121"), leading=14)

small = PS("Small",
    fontName="Helvetica", fontSize=8.5,
    textColor=HexColor("#444444"), leading=12)

# ─────────────────────────────────────────────────────────────────────────────
# Helper: coloured banner
# ─────────────────────────────────────────────────────────────────────────────
def banner(text, style, bg, pad=7):
    tbl = Table([[Paragraph(text, style)]], colWidths=[TW])
    tbl.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), bg),
        ("TOPPADDING",    (0,0), (-1,-1), pad),
        ("BOTTOMPADDING", (0,0), (-1,-1), pad),
        ("LEFTPADDING",   (0,0), (-1,-1), 12),
        ("RIGHTPADDING",  (0,0), (-1,-1), 12),
    ]))
    return tbl

# ─────────────────────────────────────────────────────────────────────────────
# Helper: section table
# ─────────────────────────────────────────────────────────────────────────────
def section_box(content_rows, header_text, header_bg, stripe_bg):
    data = [[Paragraph(f"<b>{header_text}</b>",
                       PS("SH", fontName="Helvetica-Bold", fontSize=9,
                          textColor=white, alignment=TA_LEFT)),
             ""]]
    data += content_rows
    col_w = [TW*0.32, TW*0.68]
    tbl = Table(data, colWidths=col_w)
    cmds = [
        ("SPAN",          (0,0), (1,0)),
        ("BACKGROUND",    (0,0), (1,0), header_bg),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
        ("RIGHTPADDING",  (0,0), (-1,-1), 8),
        ("GRID",          (0,1), (-1,-1), 0.4, C_GRAY_MID),
        ("LINEBELOW",     (0,0), (1,0), 1, white),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]
    for i in range(1, len(data)):
        bg = stripe_bg if i % 2 == 0 else white
        cmds.append(("BACKGROUND", (0,i), (1,i), bg))
    tbl.setStyle(TableStyle(cmds))
    return tbl

# ─────────────────────────────────────────────────────────────────────────────
# Helper: draw a box with label (using Rect + String)
# ─────────────────────────────────────────────────────────────────────────────
def draw_box(d, cx, cy, w, h, fill, stroke, text, font_size=8.5, text_color=None):
    if text_color is None:
        text_color = white
    r = Rect(cx - w/2, cy - h/2, w, h,
             fillColor=fill, strokeColor=stroke, strokeWidth=0.8)
    d.add(r)
    # Simple single-line text
    s = String(cx, cy - font_size * 0.38, text,
               fontName="Helvetica-Bold", fontSize=font_size,
               fillColor=text_color, textAnchor="middle")
    d.add(s)

def draw_small_box(d, cx, cy, w, h, fill, stroke, text, font_size=7.5, text_color=None):
    if text_color is None:
        text_color = black
    r = Rect(cx - w/2, cy - h/2, w, h,
             fillColor=fill, strokeColor=stroke, strokeWidth=0.5)
    d.add(r)
    s = String(cx, cy - font_size * 0.38, text,
               fontName="Helvetica", fontSize=font_size,
               fillColor=text_color, textAnchor="middle")
    d.add(s)

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 1 – Classification Tree
# ─────────────────────────────────────────────────────────────────────────────
def make_tree_diagram():
    dw = float(TW)
    dh = 220.0
    d = Drawing(dw, dh)

    cx = dw / 2.0

    # Root
    root_y = dh - 28.0
    draw_box(d, cx, root_y, 150, 28, C_BLUE_DARK, HexColor("#0A1E40"), "LIPIDS", 14, white)

    # Branch centres
    bx = [cx - 185.0, cx, cx + 185.0]
    by = root_y - 68.0
    b_colors = [C_GREEN, C_PURPLE, C_ORANGE]
    b_labels = ["1. SIMPLE LIPIDS", "2. COMPOUND LIPIDS", "3. DERIVED LIPIDS"]
    b_w = [115, 128, 115]

    for i in range(3):
        # Connector from root
        d.add(Line(cx, root_y - 14, bx[i], by + 14,
                   strokeColor=b_colors[i], strokeWidth=1.5))
        draw_box(d, bx[i], by, b_w[i], 26, b_colors[i],
                 HexColor("#000000"), b_labels[i], 9.5, white)

    # Leaf nodes
    leaf_y = by - 58.0
    leaf_data = [
        # (parent_x, leaf_x, label, fill, stroke_c)
        (bx[0], bx[0]-30, "Fats\n(Triglycerides)", C_GREEN_L, C_GREEN),
        (bx[0], bx[0]+38, "Waxes", C_GREEN_L, C_GREEN),
        (bx[1], bx[1]-55, "Phospholipids", C_PURPLE_L, C_PURPLE),
        (bx[1], bx[1]+2,  "Glycolipids", C_PURPLE_L, C_PURPLE),
        (bx[1], bx[1]+60, "Lipoproteins", C_PURPLE_L, C_PURPLE),
        (bx[2], bx[2]-38, "Fatty Acids", C_ORANGE_L, C_ORANGE),
        (bx[2], bx[2]+38, "Sterols &\nHormones", C_ORANGE_L, C_ORANGE),
    ]
    lw, lh = 78.0, 24.0
    for px, lx, label, fill, sc in leaf_data:
        # connector
        d.add(Line(px, by - 13, lx, leaf_y + lh/2,
                   strokeColor=sc, strokeWidth=0.9))
        # box
        r = Rect(lx - lw/2, leaf_y - lh/2, lw, lh,
                 fillColor=fill, strokeColor=sc, strokeWidth=0.5)
        d.add(r)
        # text (handle newline manually)
        lines = label.split("\n")
        if len(lines) == 1:
            d.add(String(lx, leaf_y - 3.5, lines[0],
                         fontName="Helvetica", fontSize=7.5,
                         fillColor=sc, textAnchor="middle"))
        else:
            d.add(String(lx, leaf_y + 2, lines[0],
                         fontName="Helvetica", fontSize=7.5,
                         fillColor=sc, textAnchor="middle"))
            d.add(String(lx, leaf_y - 8, lines[1],
                         fontName="Helvetica", fontSize=7.5,
                         fillColor=sc, textAnchor="middle"))

    # Extra derived items below
    extra_y = leaf_y - 40.0
    extra_items = [
        (bx[2]-38, "Vitamins A,D,E,K"),
        (bx[2]+38, "Bile Acids &\nProstaglandins"),
    ]
    ew, eh = 85.0, 22.0
    for ex, elabel in extra_items:
        d.add(Line(bx[2], leaf_y - lh/2, ex, extra_y + eh/2,
                   strokeColor=C_ORANGE, strokeWidth=0.7))
        r = Rect(ex - ew/2, extra_y - eh/2, ew, eh,
                 fillColor=C_ORANGE_L, strokeColor=C_ORANGE, strokeWidth=0.4)
        d.add(r)
        lines = elabel.split("\n")
        if len(lines) == 1:
            d.add(String(ex, extra_y - 3, lines[0],
                         fontName="Helvetica", fontSize=7,
                         fillColor=C_ORANGE, textAnchor="middle"))
        else:
            d.add(String(ex, extra_y + 2.5, lines[0],
                         fontName="Helvetica", fontSize=7,
                         fillColor=C_ORANGE, textAnchor="middle"))
            d.add(String(ex, extra_y - 7, lines[1],
                         fontName="Helvetica", fontSize=7,
                         fillColor=C_ORANGE, textAnchor="middle"))

    return d

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 2 – Phospholipid (amphipathic structure)
# ─────────────────────────────────────────────────────────────────────────────
def make_phospholipid_diagram():
    dw = float(TW * 0.48)
    dh = 150.0
    d = Drawing(dw, dh)
    mx = dw / 2.0

    # Hydrophilic head
    head_y = dh - 32.0
    r = Rect(mx - 44, head_y - 20, 88, 40,
             fillColor=HexColor("#AED6F1"), strokeColor=C_BLUE_MID, strokeWidth=1)
    d.add(r)
    d.add(String(mx, head_y + 2, "POLAR HEAD",
                 fontName="Helvetica-Bold", fontSize=8.5,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))
    d.add(String(mx, head_y - 10, "(Phosphate + Nitrogen base)",
                 fontName="Helvetica", fontSize=7,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))

    # Glycerol
    gly_y = head_y - 46.0
    r2 = Rect(mx - 22, gly_y - 11, 44, 22,
              fillColor=HexColor("#F9E79F"), strokeColor=HexColor("#B7950B"), strokeWidth=0.8)
    d.add(r2)
    d.add(String(mx, gly_y - 4, "Glycerol",
                 fontName="Helvetica-Bold", fontSize=8,
                 fillColor=HexColor("#7D6608"), textAnchor="middle"))

    # Connector head to glycerol
    d.add(Line(mx, head_y - 20, mx, gly_y + 11,
               strokeColor=C_BLUE_MID, strokeWidth=1.5))

    # Two tails
    tail_top = gly_y - 11.0
    tail_bot = tail_top - 52.0
    for tx in [mx - 18, mx + 18]:
        d.add(Line(tx, tail_top, tx, tail_bot,
                   strokeColor=C_ORANGE, strokeWidth=3))

    # Tail labels
    d.add(String(mx - 18, tail_bot - 9, "Tail 1",
                 fontName="Helvetica", fontSize=7,
                 fillColor=C_ORANGE, textAnchor="middle"))
    d.add(String(mx + 18, tail_bot - 9, "Tail 2",
                 fontName="Helvetica", fontSize=7,
                 fillColor=C_ORANGE, textAnchor="middle"))

    # Annotations
    d.add(String(mx, dh - 8, "HYDROPHILIC HEAD  (Water-loving)",
                 fontName="Helvetica-BoldOblique", fontSize=7,
                 fillColor=C_BLUE_MID, textAnchor="middle"))
    d.add(String(mx, 5, "HYDROPHOBIC TAILS  (Water-fearing)",
                 fontName="Helvetica-BoldOblique", fontSize=7,
                 fillColor=C_ORANGE, textAnchor="middle"))

    return d

# ─────────────────────────────────────────────────────────────────────────────
# DIAGRAM 3 – Triglyceride structure
# ─────────────────────────────────────────────────────────────────────────────
def make_triglyceride_diagram():
    dw = float(TW * 0.52)
    dh = 150.0
    d = Drawing(dw, dh)

    mx = dw * 0.3
    fa_x = dw * 0.75

    # Title
    d.add(String(dw/2, dh - 8, "TRIGLYCERIDE STRUCTURE",
                 fontName="Helvetica-Bold", fontSize=9,
                 fillColor=C_GREEN, textAnchor="middle"))

    # Glycerol boxes
    gy = [dh - 45.0, dh - 75.0, dh - 105.0]
    labels = ["C1 – OH", "C2 – OH", "C3 – OH"]
    for y, lbl in zip(gy, labels):
        r = Rect(mx - 28, y - 11, 56, 22,
                 fillColor=HexColor("#F9E79F"),
                 strokeColor=HexColor("#B7950B"), strokeWidth=0.8)
        d.add(r)
        d.add(String(mx, y - 4, lbl,
                     fontName="Helvetica-Bold", fontSize=8,
                     fillColor=HexColor("#7D6608"), textAnchor="middle"))

    # Glycerol label
    d.add(String(mx, dh - 22, "GLYCEROL",
                 fontName="Helvetica-Bold", fontSize=8,
                 fillColor=C_BLUE_DARK, textAnchor="middle"))

    # Fatty acid tails
    for y in gy:
        # Ester bond connector
        d.add(Line(mx + 28, y, fa_x - 42, y,
                   strokeColor=HexColor("#888888"), strokeWidth=0.7))
        # ester bond label
        d.add(String(mx + 50, y + 5, "ester",
                     fontName="Helvetica-Oblique", fontSize=6,
                     fillColor=HexColor("#999999"), textAnchor="middle"))
        # Fatty acid bar
        d.add(Line(fa_x - 42, y, fa_x + 42, y,
                   strokeColor=C_ORANGE, strokeWidth=4))

    # Fatty acid label
    d.add(String(fa_x, dh - 22, "FATTY ACIDS  (×3)",
                 fontName="Helvetica-Bold", fontSize=8,
                 fillColor=C_ORANGE, textAnchor="middle"))

    # Formula at bottom
    d.add(String(dw/2, 5, "Triglyceride = Glycerol + 3 Fatty Acids  (via Ester Bonds)",
                 fontName="Helvetica-Bold", fontSize=7.5,
                 fillColor=C_GREEN, textAnchor="middle"))

    return d


# ─────────────────────────────────────────────────────────────────────────────
# BUILD STORY
# ─────────────────────────────────────────────────────────────────────────────
story = []

# ── COVER BANNER ─────────────────────────────────────────────────────────────
cover = Table(
    [[Paragraph("CLASSIFICATION OF LIPIDS", title_style)],
     [Paragraph("1st Year MBBS  |  Biochemistry  |  4-Mark Exam Study Guide", subtitle_style)]],
    colWidths=[TW]
)
cover.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), C_BLUE_DARK),
    ("TOPPADDING",    (0,0), (-1,-1), 12),
    ("BOTTOMPADDING", (0,0), (-1,-1), 12),
    ("LEFTPADDING",   (0,0), (-1,-1), 14),
    ("RIGHTPADDING",  (0,0), (-1,-1), 14),
]))
story.append(cover)
story.append(Spacer(1, 8))

# ── DEFINITION ───────────────────────────────────────────────────────────────
story.append(banner("DEFINITION", h1, C_BLUE_DARK))
story.append(Spacer(1, 4))
story.append(Paragraph(
    "<b>Lipids</b> are <b>organic biomolecules</b> that are <b>insoluble in water</b> but "
    "<b>soluble in organic solvents</b> (ether, chloroform, benzene). "
    "They contain <b>Carbon, Hydrogen, Oxygen</b> (some also have N, P, S). "
    "They serve as energy stores, membrane components, hormones, and signalling molecules.",
    body))
story.append(Spacer(1, 8))

# ── MAIN CLASSIFICATION TREE DIAGRAM ─────────────────────────────────────────
story.append(banner("CLASSIFICATION OVERVIEW   (Mind Map / Tree Diagram)", h1, C_BLUE_MID))
story.append(Spacer(1, 6))
story.append(make_tree_diagram())
story.append(Spacer(1, 8))

# ── 1. SIMPLE LIPIDS ─────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("1.  SIMPLE LIPIDS", h1, C_GREEN),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Esters of <b>fatty acids + alcohol ONLY</b>. No extra group attached.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Fats (Triglycerides)</b>", body_bold),
             Paragraph("3 Fatty acids + Glycerol (via ester bonds). Main <b>energy storage</b> form in body. "
                       "1 g fat = 9 kcal. Examples: body fat, butter, ghee, olive oil.", small)],
            [Paragraph("<b>Waxes</b>", body_bold),
             Paragraph("1 Fatty acid + Long-chain monohydric alcohol. "
                       "Water-repellent coating. "
                       "Examples: Beeswax (Myricyl palmitate), Earwax (cerumen), Lanolin (skin), Carnauba wax.", small)],
        ],
        "TYPE   vs   DETAILS", C_GREEN, C_GREEN_L
    ),
    Spacer(1, 6),
]))

# Triglyceride diagram
story.append(Paragraph("<b>Triglyceride Structure:</b>", h2))
story.append(make_triglyceride_diagram())
story.append(Spacer(1, 8))

# ── 2. COMPOUND LIPIDS ───────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("2.  COMPOUND LIPIDS  (Complex Lipids)", h1, C_PURPLE),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Consist of simple lipid + <b>one additional non-lipid group</b>.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Phospholipids</b>", body_bold),
             Paragraph("FA + Glycerol + <b>Phosphate + Nitrogenous base</b>. "
                       "Form <b>cell membrane bilayer</b> (amphipathic). "
                       "E.g., Lecithin (PC), Cephalin (PE), Sphingomyelin. "
                       "Lung surfactant = DPPC (dipalmitoyl lecithin).", small)],
            [Paragraph("<b>Glycolipids</b>", body_bold),
             Paragraph("FA + Sphingosine + <b>Carbohydrate (sugar)</b>. "
                       "Found in <b>brain and nerve tissue</b>. "
                       "E.g., Cerebrosides (glucose/galactose), Gangliosides.", small)],
            [Paragraph("<b>Lipoproteins</b>", body_bold),
             Paragraph("Lipid + <b>Protein (apoprotein)</b>. "
                       "Transport lipids in <b>blood</b> (lipids can't dissolve in plasma alone). "
                       "E.g., Chylomicrons, VLDL, IDL, LDL, HDL.", small)],
            [Paragraph("<b>Sulfolipids</b>", body_bold),
             Paragraph("Contain a <b>sulfate (-SO4)</b> group. Found in brain tissue.", small)],
            [Paragraph("<b>Aminolipids</b>", body_bold),
             Paragraph("Contain an <b>amino (-NH2)</b> group. Found in tissues.", small)],
        ],
        "TYPE   vs   DETAILS", C_PURPLE, C_PURPLE_L
    ),
    Spacer(1, 6),
]))

# Phospholipid diagram + notes side by side
story.append(Paragraph("<b>Phospholipid (Amphipathic) Structure:</b>", h2))
diag_row = Table(
    [[make_phospholipid_diagram(),
      Paragraph(
          "<b>Key Points:</b><br/>"
          "- Has a <b>hydrophilic (polar) head</b> - faces water/outside<br/>"
          "- Has <b>hydrophobic (non-polar) tails</b> - face inward<br/>"
          "- This amphipathic property = <b>lipid bilayer</b> formation<br/>"
          "- Bilayer = basic unit of ALL cell membranes<br/>"
          "- Lecithin = most abundant phospholipid in body<br/>"
          "- DPPC = lung surfactant (prevents alveolar collapse)<br/>"
          "- Cephalin = important in blood clotting",
          PS("Note", fontName="Helvetica", fontSize=8.5,
             textColor=HexColor("#212121"), leading=14)
      )]],
    colWidths=[TW*0.46, TW*0.54]
)
diag_row.setStyle(TableStyle([
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ("LEFTPADDING",   (0,0), (-1,-1), 4),
    ("BACKGROUND",    (1,0), (1,0), C_PURPLE_L),
    ("TOPPADDING",    (1,0), (1,0), 10),
    ("BOTTOMPADDING", (1,0), (1,0), 10),
    ("LEFTPADDING",   (1,0), (1,0), 10),
]))
story.append(diag_row)
story.append(Spacer(1, 8))

# ── 3. DERIVED LIPIDS ────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("3.  DERIVED LIPIDS", h1, C_ORANGE),
    Spacer(1, 4),
    Paragraph(
        "<b>Definition:</b> Products obtained by <b>hydrolysis</b> (breakdown) of simple or compound lipids. "
        "They do NOT contain ester linkage but have lipid-like properties.",
        body),
    Spacer(1, 4),
    section_box(
        [
            [Paragraph("<b>Fatty Acids</b>", body_bold),
             Paragraph("Basic building blocks of all lipids. "
                       "Saturated: Palmitic (C16:0), Stearic (C18:0). "
                       "Unsaturated: Oleic (C18:1), Linoleic (C18:2, essential), Arachidonic (C20:4).", small)],
            [Paragraph("<b>Sterols</b>", body_bold),
             Paragraph("<b>Cholesterol</b> - most important. Animal sterols. "
                       "Phytosterols (plants), Ergosterol (fungi - precursor of Vit D). "
                       "Cholesterol = precursor of steroid hormones, bile acids, Vit D.", small)],
            [Paragraph("<b>Glycerol</b>", body_bold),
             Paragraph("3-carbon backbone released on hydrolysis of triglycerides.", small)],
            [Paragraph("<b>Fat-Soluble Vitamins</b>", body_bold),
             Paragraph("<b>A, D, E, K</b> - stored in liver and adipose tissue. "
                       "NOT excreted in urine - risk of toxicity if overdosed.", small)],
            [Paragraph("<b>Steroid Hormones</b>", body_bold),
             Paragraph("All derived from <b>Cholesterol</b>. "
                       "Cortisol, Aldosterone (adrenal cortex); "
                       "Testosterone, Estrogen, Progesterone (gonads).", small)],
            [Paragraph("<b>Bile Acids</b>", body_bold),
             Paragraph("Made in liver from cholesterol. "
                       "E.g., Cholic acid, Chenodeoxycholic acid. "
                       "Function: emulsify fats for digestion and absorption.", small)],
            [Paragraph("<b>Prostaglandins</b>", body_bold),
             Paragraph("20-carbon compounds from Arachidonic acid. "
                       "Involved in inflammation, pain, fever, platelet aggregation. "
                       "Target of NSAIDs (aspirin, ibuprofen).", small)],
        ],
        "TYPE   vs   DETAILS", C_ORANGE, C_ORANGE_L
    ),
    Spacer(1, 6),
]))

# ── SUMMARY TABLE ─────────────────────────────────────────────────────────────
story.append(banner("EXAM SUMMARY TABLE  -  Write This in Your Exam!", h1, C_BLUE_DARK))
story.append(Spacer(1, 5))

hdr = lambda t: Paragraph(f"<b>{t}</b>",
    PS("SH2", fontName="Helvetica-Bold", fontSize=9, textColor=white))

sum_data = [
    [hdr("Class"), hdr("Definition"), hdr("Examples"), hdr("Main Function")],
    [Paragraph("<b>Simple</b>",
               PS("GH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_GREEN)),
     Paragraph("FA + Alcohol only<br/>(ester bond)", small),
     Paragraph("Triglycerides, Waxes", small),
     Paragraph("Energy storage, waterproofing", small)],
    [Paragraph("<b>Compound</b>",
               PS("PH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_PURPLE)),
     Paragraph("Simple lipid +<br/>extra non-lipid group", small),
     Paragraph("Phospholipids,<br/>Glycolipids, Lipoproteins", small),
     Paragraph("Cell membranes,<br/>lipid transport in blood", small)],
    [Paragraph("<b>Derived</b>",
               PS("OH", fontName="Helvetica-Bold", fontSize=8.5, textColor=C_ORANGE)),
     Paragraph("Hydrolysis products<br/>of above", small),
     Paragraph("Cholesterol, Fatty acids,<br/>Vitamins A/D/E/K,<br/>Steroid hormones", small),
     Paragraph("Hormones, vitamins,<br/>bile salts, signalling", small)],
]
sum_tbl = Table(sum_data, colWidths=[TW*0.13, TW*0.24, TW*0.32, TW*0.31])
sum_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0), C_BLUE_DARK),
    ("BACKGROUND",    (0,1), (-1,1), C_GREEN_L),
    ("BACKGROUND",    (0,2), (-1,2), C_PURPLE_L),
    ("BACKGROUND",    (0,3), (-1,3), C_ORANGE_L),
    ("GRID",          (0,0), (-1,-1), 0.5, C_GRAY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(sum_tbl)
story.append(Spacer(1, 8))

# ── MEMORY TRICKS ─────────────────────────────────────────────────────────────
story.append(KeepTogether([
    banner("MEMORY TRICKS", h1, HexColor("#C0392B")),
    Spacer(1, 5),
    Table(
        [[Paragraph(
            "<b>Remember 3 Classes:  S - C - D</b><br/><br/>"
            "<font color='#1B7A3E'><b>S</b></font> = Simple  (Fats + Waxes)<br/>"
            "<font color='#6A1B9A'><b>C</b></font> = Compound  (Phospholipids, Glycolipids, Lipoproteins)<br/>"
            "<font color='#B85C00'><b>D</b></font> = Derived  (Cholesterol, Fatty acids, Vitamins A/D/E/K)",
            PS("M1", fontName="Helvetica-Bold", fontSize=10.5,
               textColor=C_BLUE_DARK, leading=18)),
          Paragraph(
            "<b>For Compound Lipids - PGL:</b><br/>"
            "<i>\"Please Give Lectures\"</i><br/>"
            "<b>P</b> = Phospholipids<br/>"
            "<b>G</b> = Glycolipids<br/>"
            "<b>L</b> = Lipoproteins<br/><br/>"
            "<b>Fat-Soluble Vitamins: ADEK</b><br/>"
            "<i>\"A Dog Eats Kibble\"</i>",
            PS("M2", fontName="Helvetica", fontSize=10,
               textColor=C_BLUE_DARK, leading=15))]],
        colWidths=[TW*0.54, TW*0.46]
    ),
    Spacer(1, 5),
]))

# ── CLINICAL POINTS ───────────────────────────────────────────────────────────
story.append(Spacer(1, 4))
story.append(banner("IMPORTANT CLINICAL POINTS  (Impress Your Examiner!)", h1, HexColor("#1A7A1A")))
story.append(Spacer(1, 5))

clinical_data = [
    ["*", Paragraph("<b>Phospholipids</b> form the <b>lipid bilayer</b> of ALL cell membranes because of their amphipathic structure.", small)],
    ["*", Paragraph("<b>Cholesterol</b> is parent molecule for: steroid hormones + bile acids + Vitamin D.", small)],
    ["*", Paragraph("<b>Triglycerides</b> = main energy storage (9 kcal/g vs 4 kcal/g for carbs/proteins).", small)],
    ["*", Paragraph("<b>Lipoproteins</b> (HDL, LDL, VLDL, Chylomicrons) transport lipids in blood since lipids alone cannot dissolve in plasma.", small)],
    ["*", Paragraph("<b>DPPC (Dipalmitoyl phosphatidylcholine)</b> = lung surfactant. Deficiency in premature babies = Respiratory Distress Syndrome (RDS).", small)],
    ["*", Paragraph("<b>Prostaglandins</b> from arachidonic acid - NSAIDs (aspirin, ibuprofen) block their synthesis = anti-inflammatory effect.", small)],
    ["*", Paragraph("<b>Fat-soluble vitamins A,D,E,K</b> - stored in liver/adipose - risk of hypervitaminosis (toxicity) if overdosed.", small)],
]
cli_tbl = Table(clinical_data, colWidths=[0.35*cm, TW - 0.35*cm])
cli_tbl.setStyle(TableStyle([
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 4),
    ("RIGHTPADDING",  (0,0), (-1,-1), 4),
    ("ROWBACKGROUNDS", (0,0), (-1,-1),
     [HexColor("#F0FFF0"), HexColor("#FFFFFF")]),
]))
story.append(cli_tbl)
story.append(Spacer(1, 8))

# ── FOOTER ────────────────────────────────────────────────────────────────────
story.append(HRFlowable(width=TW, color=C_BLUE_DARK, thickness=1))
story.append(Spacer(1, 4))
story.append(Paragraph(
    "1st Year MBBS  |  Biochemistry  |  Classification of Lipids Study Guide  |  Best of Luck in Your Exams!",
    PS("Footer", fontName="Helvetica-Oblique", fontSize=8,
       textColor=HexColor("#888888"), alignment=TA_CENTER)
))

# ── BUILD ─────────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF saved to: {OUTPUT}")
Reading File
Editing File

~/lipids-study-guide/generate_pdf.py

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/lipids-study-guide/generate_pdf.py'
Running Command

cat > /home/daytona/workspace/lipids-study-guide/generate_pdf.py << 'PYEOF' from…

Running Command

python3 /home/daytona/workspace/lipids-study-guide/generate_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/lipids-study-guide/Lipid_Classification_Study_Gui…

Your study guide PDF is ready! Here's your download link:

Lipid Classification Study Guide

PDF Document · PDF


What's inside the PDF:
SectionWhat you get
Cover BannerTitle + "1st Year MBBS - Biochemistry - 4-Mark Exam Study Guide"
DefinitionClean, exam-ready definition of lipids
Mind Map / Tree DiagramFull colour branching diagram showing all 3 classes and their sub-types at a glance
1. Simple LipidsColour-coded table (green) + Triglyceride structure diagram
2. Compound LipidsColour-coded table (purple) + Phospholipid amphipathic structure diagram with key points
3. Derived LipidsColour-coded table (orange) covering all 7 derived types
Exam Summary Table3-row quick-reference table - perfect to copy in your exam answer
Memory TricksS-C-D trick, PGL trick for compound lipids, ADEK trick for vitamins
Clinical Points7 important clinical facts to impress your examiner (RDS, NSAIDs, lipoproteins, etc.)
FooterMotivational sign-off
The whole guide is colour-coded - green for Simple, purple for Compound, orange for Derived - so it's very easy to read and remember. Good luck in your exam!
This is a shared conversation. Sign in to Orris to start your own chat.