Schafmeister Touts Lisp-Designed Filter to Eclipse Reverse Osmosis

CANDO: A Compiled Programming Language for Computer-Aided Nanomaterial Design and Optimization — European Lisp Symposium

European Lisp Symposium

Rigid macromolecular channels designed in CANDO achieve ten times the water flux of natural aquaporins and desalt seawater under gravity alone, challenging conventional high-pressure filtration systems.

AI-assisted summary of CANDO: A Compiled Programming Language for Computer-Aided Nanomaterial Design and Optimization — original source. Check the original for full context.

Source published:

Key ideas

  • CANDO is a compiled Common Lisp domain-specific language built on the Clasp implementation that integrates 239 first-class C++ chemistry classes and LLVM code generation for macromolecular design. (6:40)
  • By replacing flexible peptide backbones with rigid 'spiroligomer' ladder macromolecules, synthetic active sites can achieve precise 3D geometry without relying on unpredictable protein folding. (0:00)
  • Simulated bio-inspired aquaporin mimics indicate water flux rates roughly 10 times higher than natural aquaporin channels, operating under minimal hydrostatic head pressure. (24:53)
  • Clasp achieves zero-overhead C++ and Common Lisp interoperability by compiling both languages to LLVM bitcode, linking them into a single module, and applying link-time inlining and fastcc calling conventions. (21:13)

Detailed notes

## Background Published on YouTube by the European Lisp Symposium on May 30, 2016, this talk was presented by Christian E. Schafmeister of Temple University at ELS 2016 in Kraków, Poland. The video description details CANDO, a compiled programming language extending the Clasp Common Lisp implementation with an LLVM backend, designed for rapid computer-aided design, 3D coordinate generation, and simulation of macromolecules and nanomaterials.

## TL;DR Chemist Christian Schafmeister introduces spiroligomers—rigid, ladder-like macromolecules designed to bypass the unpredictable folding and instability of natural proteins. Facing a combinatorial design space of up to 10^160 candidate molecules, he built CANDO on top of Clasp Common Lisp to blend dynamic, symbolic Lisp programming with zero-overhead C++ and LLVM native code compilation. Through a live demo in Emacs and SLIME, Schafmeister demonstrates the end-to-end design, energy minimization, and solvation of an artificial aquaporin-like water purification membrane. Computational simulations reveal that this biomimetic channel could achieve an order-of-magnitude higher water flux than biological aquaporins, potentially revolutionizing desalination and municipal water filtration.

## Atmosphere & style The presentation carries the energetic, enthusiastic vibe of an academic hacker bridging deep organic chemistry with cutting-edge compiler engineering. Schafmeister delivers his ideas with candid humor, irreverently dismissing fragile proteins as 'Jell-O like things' and criticizing Python bindings on high-performance C++ libraries as 'putting a jet engine behind a donkey.' Watching him hop interactively into a SLIME debugger mid-optimization makes the talk feel refreshingly hands-on, blending high-stakes scientific ambition—such as averting civilizational water crises—with genuine hacker delight.

## Bulletin - [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) CANDO is a compiled Common Lisp domain-specific language built on the Clasp implementation that integrates 239 first-class C++ chemistry classes and LLVM code generation for macromolecular design. - [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) By replacing flexible peptide backbones with rigid 'spiroligomer' ladder macromolecules, synthetic active sites can achieve precise 3D geometry without relying on unpredictable protein folding. - [24:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1493s) Simulated bio-inspired aquaporin mimics indicate water flux rates roughly 10 times higher than natural aquaporin channels, operating under minimal hydrostatic head pressure. - [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Clasp achieves zero-overhead C++ and Common Lisp interoperability by compiling both languages to LLVM bitcode, linking them into a single module, and applying link-time inlining and fastcc calling conventions.

## Key takeaways - [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) Natural proteins are soft, fragile, and difficult to engineer predictably because single-bond flexible chains fold in complex, temperamental ways. - [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) Spiroligomers use pairs of chemical bonds between ring building blocks to create rigid ladder-like architectures that position catalytic groups with atomic precision. - [02:04](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=124s) A proof-of-concept synthetic catalyst modeled after acetylcholinesterase accelerated reaction steps up to 2,500-fold, demonstrating enzyme-like behavior without protein scaffolds. - [02:04](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=124s) The combinatorial configuration space for designed macromolecules reaches between 10^60 and 10^160 possibilities, making brute-force library screening impossible and demanding native-speed Monte Carlo design loops. - [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) CANDO extends Clasp Common Lisp by integrating 155,000 lines of custom C++ and exposing 239 chemistry classes directly into the runtime alongside primitive Lisp types. - [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) Tracing garbage collection is essential for computational chemistry software because molecular graphs contain cyclic references that break simple reference counting. - [09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) CANDO performs symbolic differentiation in Common Lisp and uses LLVM native compilation to generate highly optimized molecular mechanics energy and derivative functions. - [09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) The platform incorporates a native implementation of SMARTS, functioning like regular expressions for molecular substructures and stereochemistry directly in Lisp. - [10:52](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=652s) Bio-inspired synthetic water filter channels modeled after aquaporin could theoretically operate up to 1,000 times more efficiently than conventional reverse osmosis systems. - [11:42](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=702s) CANDO converts 2D ChemDraw topology files into fully minimized 3D coordinate structures using an interactive nonlinear optimization engine within SLIME. - [19:35](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1175s) Five grams of designed channel material could form a defect-free filtration membrane covering the area of a football field, permeable under just 27 feet of water head pressure. - [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Cross-language LLVM bitcode compilation enables Clasp to inline C++ into Common Lisp and utilize the fastcc calling convention with zero interop overhead. - [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) A source code scraper parsing the CL_DEFUN macro automatically generates C++ wrappers, exposing thousands of native functions to the Common Lisp environment. - [23:27](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1407s) CANDO serves as a high-level automation platform to construct, vary, and dispatch molecular dynamics simulations across supercomputing clusters running engines like NAMD and OpenMM. - [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) Rigid sub-nanometer channel constrictions reject dissolved salt ions by imposing an insurmountable energetic penalty against stripping their coordinating hydration shells. - [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) Unlike biological aquaporins that degrade within days, synthetic ladder macromolecules offer long-term chemical durability suitable for continuous industrial cross-flow filtration.

## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) The Limitations of Natural Proteins and the Invention of Spiroligomers

Christian Schafmeister begins by explaining how natural macromolecular systems function, highlighting biological examples such as antibodies—which adapt and evolve binding pockets when the body faces viral infections—and membrane channels that regulate transport in and out of cells. While these biological structures are exceptionally capable, working with proteins directly presents massive engineering bottlenecks. Schafmeister recalls his background in biophysics and large-protein design:

> “I made one of the first unnatural large proteins by designing it on paper, designing the gene, sticking to bacteria, expressing it, crystallizing it, but the thing was a molecular boat anchor, took me four years to make it, and I didn't know how to make another one, because proteins are horrible to work with.”

Proteins are soft, squishy, "Jell-O like things" that operate reliably only within narrow physiological windows (such as holding them at 37–38 °C for a month to generate organisms like eagles, humans, or trees). Take them out of that environment for even a few minutes, and they turn into something cooked and delicious, but nonfunctional.

To overcome this, Schafmeister invented an alternative chemical strategy roughly 13 to 14 years earlier: building stiff macromolecular scaffolds out of ring-shaped building blocks connected by pairs of bonds (bis-peptides or "spiroligomers") rather than flexible, single-bond linkages. Because flexible chains fold unpredictably, creating rigid ladder-like architectures allows researchers to hang functional groups off the scaffold with atomic-level geometric precision.

```mermaid flowchart LR accTitle: Protein vs Ladder Macromolecule Folding accDescr: Comparison between flexible peptide chains requiring complex folding and rigid ladder oligomers with precise geometry. subgraph NaturalProteins["Natural Proteins"] direction TB A1["Single-bond flexible chain"] --> A2["Unpredictable 3D folding"] A2 --> A3["Soft, squishy active site"] end subgraph Spiroligomers["Rigid Ladder Macromolecules"] direction TB B1["Ring building blocks"] --> B2["Pairs of bonds (rigid ladder)"] B2 --> B3["Fixed spatial catalytic pocket"] end ```

- Flexible peptide chains require unpredictable folding pathways, whereas pairs of bonds force rigid ladder-like geometry without relying on self-folding. - Rigid backbones allow catalytic side chains to be positioned precisely in three dimensions to form artificial enzyme active sites and binding pockets.

---

[02:04](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=124s) Artificial Enzymes and the Need for a Domain-Specific Language

To demonstrate the capability of this architecture, Schafmeister showcases a small designed catalyst designed to mimic acetylcholinesterase. In the human brain, acetylcholinesterase rapidly hydrolyzes the neurotransmitter acetylcholine between individual nerve pulses to clear the synaptic cleft for subsequent signals. When exposed to organophosphorus nerve agents, this enzyme is blocked, causing neurotransmitter buildup and nervous system failure. With funding from the Department of Defense, Schafmeister’s lab worked on understanding this mechanism and designing synthetic scavengers capable of detoxifying nerve agents.

Their synthetic catalyst fixes three catalytic chemical groups in an exact 3D spatial constellation. When tested, the molecule accelerated its first target reaction step roughly 2,500-fold and the second step about 150-fold, demonstrating genuine enzyme-like catalytic behavior without being consumed. However, natural enzymes accelerate chemical reactions by trillions of times:

> “There's wizardry going on in here, and we haven't achieved that yet, but these are very tiny, and so I need to make larger things to do the sorts of things that our enzymes do.”

Scaling up to larger macromolecules involves connecting multiple modular segments, resulting in systems with astronomical numbers of possible stereochemical and sequence configurations. Schafmeister points out that traditional computational materials design relies on screening virtual libraries through successive computational filters. While viable for small molecules, the configuration space for these macromolecular scaffolds ranges between $10^{60}$ and $10^{160}$ possible molecules—far too large to enumerate, let alone filter exhaustively. Searching such enormous combinatorial landscapes requires starting from a point and running tight Monte Carlo optimization loops on a single processor.

The practical barrier turned out to be the design software itself. Schafmeister initially built custom graphical interfaces and C++ libraries linked through Python wrappers. Every time his synthetic chemistry students introduced a new reaction or attached new building blocks, the rigid software pipeline broke, requiring tedious code rewrites. He concluded that instead of ad-hoc scripts, the field required an expressive programming language:

> “I finally decided what I need is a language; I need a programming language that does for molecules what things like Mathematica or MATLAB does for mathematics or physics.”

- DoD funding supported the development of synthetic enzymes capable of neutralizing chemical nerve agents. - The proof-of-concept catalyst achieved up to a 2,500-fold acceleration on chemical transformation steps. - Exploring a combinatorial design space of $10^{60}$ to $10^{160}$ candidate molecules requires tight, native-speed Monte Carlo loops rather than brute-force library generation.

---

[06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) CANDO Architecture: Built on Clasp Common Lisp

To solve the architectural challenge, Schafmeister designed CANDO (Computer-Aided Nanomaterial Design and Optimization). CANDO runs as an extension of Clasp, a Common Lisp implementation designed specifically for seamless C++ interoperability using an LLVM compiler backend. While acknowledging with a chuckle that Clasp is essentially the thirteenth active Common Lisp implementation in the world, Schafmeister emphasizes that it uniquely fits his requirements: integrating deeply with massive existing C++ scientific libraries without having to rewrite them.

```mermaid flowchart TD accTitle: CANDO and Clasp Software Hierarchy accDescr: Structural composition of CANDO showing Common Lisp code from ECL, C++ core code, LLVM backend, and domain-specific chemistry classes. subgraph Foundation["Clasp Common Lisp Core"] direction TB ECL["26k lines Common Lisp (from ECL)"] CPP_Core["150k lines C++ Source"] LLVM["LLVM Backend Native Code Gen"] ECL --- CPP_Core CPP_Core --- LLVM end subgraph CandoExt["CANDO Chemistry Extensions"] direction TB CPP_Cando["155k lines CANDO C++ Core"] Classes["239 First-Class C++ Classes\n(Atoms, Bonds, Force Fields, Stereochem)"] CL_Code["CANDO Common Lisp Domain Code"] CPP_Cando --> Classes Classes --> CL_Code end Foundation --> CandoExt ```

CANDO extends Clasp by incorporating 155,000 lines of custom C++ into Clasp’s base (which consists of roughly 150,000 lines of C++ and 26,000 lines of Common Lisp borrowed from Embeddable Common Lisp / ECL). Through template metaprogramming, CANDO registers 239 specialized C++ classes directly into the Common Lisp runtime as first-class, garbage-collected types alongside primitives like `fixnum`, `double-float`, and `hash-table`.

- **First-Class Chemistry Classes**: Atoms, bonds, residues, molecules, stereocenters, and force-field parameters exist natively as garbage-collected objects within Lisp. - **Garbage Collection Needs**: Because molecules are graphs with cyclic structures, reference counting fails and causes memory leaks; a tracing garbage collector is strictly necessary. - **Built-in Physics Optimization**: CANDO integrates non-linear energy minimization directly, allowing researchers to incorporate complex force-field energy functions and leverage symbolic algebra packages like Maxima to derive mathematical energy terms.

[09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) Chemistry Tooling, Native Code Generation, and Library Integration

Christian Schafmeister outlines the advanced capabilities built directly into CANDO, starting with symbolic manipulation. The system performs symbolic differentiation entirely in Common Lisp, automatically generating fast native code to evaluate molecular energy functions alongside their first and second derivatives. It also features automatic atom type assignment for molecular mechanics energy calculations, stereochemistry handling, and an implementation of SMARTS—a query language functioning like regular expressions for identifying molecular substructures and fragments. Schafmeister emphasizes that although he did not invent SMARTS, implementing it natively in Clasp and CANDO allows users to create powerful, fast, and scalable chemistry tools purely in Common Lisp.

```mermaid flowchart TD accTitle: CANDO Architecture and Integrations accDescr: Diagram illustrating how CANDO combines symbolic math, chemistry rules, and external C++ libraries within Clasp Common Lisp. subgraph LispEnv["CANDO (Clasp Common Lisp)"] A["Symbolic Differentiation"] --> B["Native LLVM Code Gen<br/>(Value, 1st & 2nd Derivatives)"] C["SMARTS Substructure Engine"] D["Stereochemistry & Atom Typing"] end subgraph ExternalLibs["External C++ Libraries"] E["OpenMM (Molecular Dynamics)"] F["Graphics, Docking & Electronic Structure"] end LispEnv <-->|"C++ Template Bindings"| ExternalLibs ```

Beyond its core analytical engine, CANDO is designed to tie into external scientific software written in C++. Schafmeister highlights OpenMM, a high-performance C++ molecular dynamics and modeling package. While OpenMM provides Python bindings, Schafmeister criticizes that architectural pairing, remarking: “they've exposed it to python but it's like putting a jet engine behind a donkey it's just horrible.” His objective with CANDO is to bridge C++ libraries directly into Common Lisp—including graphics engines, docking toolkits, and electronic structure calculation codes—so researchers can drive high-performance computational pipelines natively from expressive Lisp code.

[10:52](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=652s) Designing Perfect Water Filters: The Aquaporin Mimic

Shifting from language mechanics to practical application, Schafmeister introduces a major research project aimed at designing macromolecular nanostructures. Highlighting the ambition of the initiative, he quips: “this is a little thing that I'm I'm working on right now that I think could Pro you know with further development could help save off the collapse of human civilization so that we have time to fix all of our other products you heard me right I think this is really really important project.” The ultimate goal is to fabricate ultra-efficient synthetic water purification membranes, an effort funded by the U.S. Army Corps of Engineers.

The design is bio-inspired, modeled after aquaporin proteins found in human kidneys that regulate osmotic balance across cell membranes by selectively conducting water while blocking all solutes. In contrast to existing energy-intensive technologies, such as the massive reverse osmosis plants constructed in California, Schafmeister explains that an artificial aquaporin-like channel could theoretically operate up to 1,000 times more efficiently. However, real-world synthesis requires proving and refining the architecture through rigorous computational modeling beforehand.

[11:42](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=702s) Live Demo: From 2D Sketch to 3D Energy Minimization in SLIME

Schafmeister transitions into a live interactive demonstration using Emacs and SLIME connected to a running CANDO/Clasp environment. He compiles and evaluates initialization code that loads ASDF systems, sets up working directories, and defines Common Lisp helper functions for geometric transformations, line maintenance, unit-cell construction, and degree-to-radian conversions.

The molecular structure originates as a chemical drawing in ChemDraw—a tool he likens to “Adobe Illustrator but for molecules.” CANDO reads the exported XML file from ChemDraw and constructs a molecular graph data structure. At import time, the graph possesses no spatial coordinates, and stereocenters (R/S designations on chiral carbon centers) are configured programmatically.

```mermaid flowchart LR accTitle: Molecular Structure Setup Pipeline accDescr: Pipeline showing the process from 2D ChemDraw XML to a fully minimized 3D coordinate structure. A["ChemDraw XML<br/>(2D Topology)"] --> B["CANDO Graph<br/>(All ~1,000 Atoms at 0,0,0)"] B --> C["Assign Random<br/>Coordinates"] C --> D["Nonlinear Energy Minimization<br/>(Steepest Descent / Conjugate Gradient / Truncated Newton)"] D --> E["Optimized 3D Single Channel"] ```

To establish a 3D conformation for the roughly 1,000 atoms starting at the origin `(0, 0, 0)`: - Atoms are initially assigned random 3D spatial coordinates. - CANDO formulates the molecule's physical constraints as an energy minimization problem, treating chemical bonds and bond angles as mechanical springs with equilibrium lengths, angles, and force tensions. - A nonlinear optimization engine written in C++ minimizes strain using a cascade of steepest descent, conjugate gradients, and a truncated Newton-Raphson minimizer. - Energy evaluation routines rely on CANDO’s JIT code generation from symbolic derivatives for performance. - Schafmeister interrupts the long-running optimization with `Ctrl-C` to demonstrate SLIME’s interactive debugger, inspecting stack backtraces and lexical arguments mid-run before loading the converged 3D single-channel structure.

[16:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=960s) Membrane Array Tiling and High-Performance Lisp Solvation

With an optimized single channel in hand, Schafmeister needs to construct a periodic membrane for molecular dynamics. The channel is designed so that water enters from one side, traverses the pore, and exits the opposite face. In Common Lisp, he tiles these units into an ordered two-dimensional membrane array.

```mermaid flowchart TD accTitle: Assembly of Solvated Membrane Simulation System accDescr: Steps to tile channels into an array, apply external water boxes, and carve out boundary regions in Common Lisp. A["Single Channel Prototype"] --> B["Tile into 2D Membrane Array"] C["Pre-equilibrated Water Box"] --> D["Tile 4x Water Boxes<br/>(Top and Bottom)"] B --> E["Assemble Composite System"] D --> E E --> F["Lisp 'molecule-in-box' Filter<br/>(Carve water layers & remove overlaps)"] F --> G["Simulation-Ready System<br/>(MD Engines: OpenMM/AMBER)"] ```

Simulating biological channels requires explicit solvation: - A pre-equilibrated box of water molecules is imported and replicated in a 2×2 tile (four water boxes total) to encompass the dimensions of the expanded membrane. - The solvent must be trimmed to create water slabs above and below the channel without colliding with the membrane itself. - Schafmeister inspects the trimming logic implemented in functions like `molecule-in-box`, which query a CLOS bounding-box class to filter out solvent molecules outside defined spatial limits. - He notes that while historically such intensive per-atom spatial filtering would have been pushed into C++ for speed, Clasp's performance makes it viable directly in Common Lisp: “I normally couple of months ago I would have never thought to do it anywhere but C++ because this has to be fast but now this is fast enough I can run it in common list”.

[19:35](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1175s) Simulation Results and Theoretical Limits of Filtration

Schafmeister presents rendering results from molecular dynamics runs that consumed several days of supercomputer compute time to simulate just a few nanoseconds of physical time. With bulk water rendered invisible, the visualization displays water molecules rapidly filling and moving through the interstitial voids of the membrane matrix. The observation that water easily permeates along both axes suggests that applying low hydrostatic pressure would produce sustained, unidirectional flow.

Schafmeister explains the quantitative implications of this synthetic architecture: - Just 5 grams of this synthesized macromolecular material—an amount small enough to hold in the palm of a hand—could be spread out into an ultra-thin, defect-free membrane covering the area of an entire soccer pitch (football field). - Approximately one-third of that entire surface area consists of open, permeable channels, effectively acting as an unobstructed pipe with a cross-section equal to one-third of a football field. - Instead of requiring the extreme hydraulic pressures needed to drive reverse osmosis, a gentle water column of merely 27 feet under gravity alone would permeate the barrier, providing enough clean drinking water for a whole city.

He concludes by asserting the thermodynamic limits of the design: “there is no theoretically there's no way in this universe to make a better membrane than this and this could be used to purify anything water all sorts of [things]”. While the material remains computational at this stage, his laboratory at Temple University is seeking research funding to synthesize the physical molecules and validate the filtration behavior experimentally.

[21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Clasp, LLVM Link-Time Optimization, and Zero-Overhead C++ Interop

Christian Schafmeister wraps up the presentation by explaining the recent progress in CANDO and Clasp, emphasizing how fresh these results are. The simulation shown on screen is only about four weeks old, representing the point where CANDO has finally become fast enough to build molecules again after several years spent heads-down building the underlying Common Lisp environment.

Turning to implementation details, Schafmeister outlines how Clasp bridges Common Lisp and C++ via LLVM. Clasp compiles its Common Lisp code to LLVM bitcode, while the C++ code is also compiled to LLVM bitcode using Clang. By linking both representations together into a single module, Clasp runs LLVM optimization passes across the language boundary. Code gets automatically inlined wherever it makes sense; when inlining is inappropriate because a function is too large, it gets promoted to the LLVM fast calling convention (`fastcc`) with optimal register matching. As Schafmeister highlights, “Basically I can hook into C++ code with no overhead compared to C++ talking to C++.”

Exposing native C++ libraries to Common Lisp requires minimal manual effort. A developer simply annotates existing C++ code with a custom `CL_DEFUN` macro. Schafmeister's source code scraper parses these annotations, automatically builds the required wrapper glue, and exports the bindings directly into the running Common Lisp environment. The entire Clasp implementation exposes thousands of functions through this automated scraping pipeline.

```mermaid flowchart TD accTitle: Clasp Cross-Language LLVM Compilation Pipeline accDescr: Pipeline showing Common Lisp and C++ compiling to LLVM bitcode, linking, running optimization passes, and outputting native binaries.

subgraph Sources ["Source Code"] CPP["C++ Source Files<br/>(annotated with CL_DEFUN)"] CL["Common Lisp Code<br/>(CANDO / User Code)"] end

subgraph LLVM_Stage ["LLVM Bitcode Generation & Linking"] ClangCompiler["Clang Compiler"] ClaspCompiler["Clasp Compiler"] Linker["LLVM Linker<br/>(Single Module)"] end

subgraph Passes ["LLVM Optimization Passes"] Inline["Full Inlining Across Boundaries"] FastCC["fastcc Calling Convention<br/>(Register Matching)"] end

CPP --> ClangCompiler -->|"Bitcode"| Linker CL --> ClaspCompiler -->|"Bitcode"| Linker Linker --> Inline --> FastCC FastCC --> Native["Optimized Native Code<br/>(Zero Overhead Interop)"] ```

- CANDO reached performance parity to design molecules after a couple of years dedicated strictly to Common Lisp infrastructure development. - Inter-language optimization is achieved by cross-compiling both C++ and Common Lisp down to LLVM bitcode and linking them before running inlining passes. - Functions not inlined are assigned the `fastcc` calling convention for register-level call speed. - The automated `CL_DEFUN` scraping tool manages thousands of wrapped C++ functions across the Clasp runtime without requiring manual Foreign Function Interface (FFI) bindings.

---

[23:27](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1407s) Molecular Dynamics Simulations and Scalable Channel Evaluation

Opening the floor to questions, Schafmeister responds to an audience inquiry about simulating membrane function. In these simulations, ions are introduced into the water regions surrounding the designed membrane channels under periodic boundary conditions. The underlying molecular mechanics engine continuously evaluates interatomic forces and moves the atoms by incremental timesteps before recalculating the forces.

Schafmeister points out that molecular dynamics simulations remain inherently compute-intensive: “It's hideously slow; it takes days to simulate nanoseconds of time, but that's what NAMD and that's what all these molecular dynamics engines do very well.” CANDO's distinct value is not replacing these high-performance dynamics engines, but serving as a rapid setup and automation layer. It can generate millions of combinatorial channel variants, dispatch parallel runs across hundreds of thousands of CPU cores on supercomputers, and automate the post-simulation analysis to determine which synthetic channels perform best.

- Molecular dynamics engines like NAMD handle numerical integration of atomic forces over multi-day runs for nanosecond-scale trajectories. - CANDO automates high-throughput setup, variation, and execution across large-scale parallel architectures. - Periodic boundary conditions are used to model infinite membrane lattices in aqueous environments.

---

[24:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1493s) Water Flux Tracking and Aquaporin Performance Comparisons

An audience member asks about how flow through the channel is quantified. Schafmeister explains that their analysis code tracks the coordinates and trajectories of individual water molecules across the periodic cell over time to compute the total membrane flux. If a synthetic channel pore is packed too tightly, water molecules cannot enter; instead, they strike the constriction point and bounce right back out into the bulk solvent.

When the pore dimensions are tuned correctly, however, the structure behaves like a sieve. Simulated water flux through these engineered channels reaches rates roughly ten times higher than natural aquaporin proteins. Schafmeister mentions that he collaborates with researchers at the University of Illinois—specifically mentioning a student named Karl—who have spent years simulating natural aquaporins and evaluating their transport dynamics.

- Membrane permeability is calculated by directly tracking the displacement vectors of individual water molecules through the pore. - Overly tight pore packing causes water molecules to reflect off the entrance rather than permeate the channel. - Optimized synthetic channels demonstrate water flux rates roughly an order of magnitude (10×) higher than biological aquaporins. - Research collaborators at the University of Illinois provide validation based on their long-term modeling of aquaporin structures.

---

[26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) Water Desalination, Ion Rejection, and Membrane Longevity

In response to a question regarding filtering molecules larger than water, Schafmeister details how these channels can be applied to seawater desalination. Seawater consists primarily of sodium and chloride ions dissolved in water, with each ion surrounded by a tightly bound shell of coordinating water molecules. For an ion to pass through a narrow channel, this hydration shell must be stripped away. By engineering the channel constriction to be narrow and rigid, the energetic penalty required to dehydrate the ion becomes too steep for the ion to enter, effectively blocking salt while allowing individual water molecules through.

The separated ions accumulate on the feed side of the membrane, meaning the system cannot run as a dead-end filter where material is simply forced against a blind barrier. Instead, it must operate using a countercurrent cross-flow setup identical to standard industrial reverse osmosis, sweeping feed seawater across the membrane face to concentrate it into brine while pure water permeates to the other side.

Comparing this technology to biological channels and existing polymer systems, Schafmeister highlights membrane durability: - Biological aquaporins denature and lose integrity over timescales of hours to days, requiring living cells to constantly degrade and recycle them. - Synthetic, rigid macromolecular channels are far more robust and could operate for extended lifetimes. - Like all filtration media, the membranes remain susceptible to surface fouling, requiring periodic back-flushing cycles to maintain throughput. - When evaluating the current commercial standard, Schafmeister pulls no punches on the state of the art: “Reverse osmosis membranes are just terrible technology; they're just the best we have.”

The session concludes as the symposium timekeeper intervenes to bring the questions and the talk to a close.

## Notable quotes > [02:04](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=124s) I need a programming language that does for molecules what things like Mathematica or MATLAB does for mathematics or physics. — Christian Schafmeister

> [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) Reverse osmosis membranes are just terrible technology; they're just the best we have. — Christian Schafmeister

> [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Basically I can hook into C++ code with no overhead compared to C++ talking to C++. — Christian Schafmeister

## Mentioned Christian E. Schafmeister, CANDO, Clasp, Common Lisp, LLVM, Clang, Embeddable Common Lisp, OpenMM, NAMD, AMBER, ChemDraw, SLIME, Emacs, ASDF, Maxima, SMARTS, Department of Defense, U.S. Army Corps of Engineers, Temple University, University of Illinois

## Video description ELS 2016, 9th European Lisp Symposium, 9-10 May 2016, Department of Computer Science, AGH University of Science and Technology, Kraków, Poland.

Christian E. Schafmeister, Chemistry Department, Temple University, 1901 N. 13th Street Philadelphia, PA.

CANDO is a compiled programming language designed for rapid prototyping and design of macromolecules and nano- meter-scale materials. CANDO provides functionality to write programs that assemble atoms and residues into new molecules and construct three-dimensional coordinates for them. CANDO also provides functionality for searching molecules for substructures, automatically assigning atom types, identifying rings, carrying out conformational search- ing, and automatically determining stereochemistry, among other things. CANDO extends the Clasp implementation of the dynamic language Common Lisp. CANDO provides classes for representing atoms, residues, molecules and ag- gregates (collections of molecules) as primitive objects that are implemented in C++ and subject to automatic memory management, like every other object within the language. CANDO inherits all of the capabilities of Clasp, including the easy incorporation of C++ libraries using a C++ tem- plate programming library. This automatically builds wrap- per code to expose the C++ functionality to the CANDO Common Lisp environment and the use of the LLVM li- brary[1] to generate fast native code. A version of CANDO can be built that incorporates the Open Message Passing Interface C++ library[2], which allows CANDO to be run on supercomputers, in order to automatically setup, start, and analyze molecular mechanics simulations on large par- allel computers. CANDO is currently available under the LGPL 2.0 license.

[Source](https://www.youtube.com/watch?v=5bQhGS8V6dQ)

中文简报

Schafmeister力推Lisp设计的滤膜,性能或超越反渗透技术 在CANDO中设计的刚性大分子通道实现了天然水通道蛋白十倍的水通量,仅凭重力即可完成海水淡化,对传统高压过滤系统发起挑战。 化学家Christian Schafmeister介绍了螺低聚物(spiroligomers)——这是一种梯形刚性大分子,旨在规避天然蛋白质不可预测的折叠与不稳定性。面对高达10^160种候选分子的组合设计空间,他在Clasp Common Lisp之上构建了CANDO,将动态符号化Lisp编程与零开销的C++及LLVM原生代码编译相结合。通过Emacs和SLIME的现场演示,Schafmeister展示了一种仿生水通道蛋白水净化膜的端到端设计、能量最小化和溶剂化过程。计算模拟表明,这种仿生通道的水通量可比生物水通道蛋白高出一个数量级,有望彻底改变海水淡化和市政水过滤领域。 CANDO是基于Clasp实现构建的编译型Common Lisp领域特定语言,集成了239个一等C++化学类以及用于大分子设计的LLVM代码生成技术。 (6:40) 通过用刚性“螺低聚物”梯形大分子替代柔性肽骨架,人工活性位点无需依赖不可预测的蛋白质折叠即可实现精确的三维几何构型。 (0:00) 模拟的仿生水通道蛋白类似物表明,在极小的静水压头下运行,其水通量约为天然水通道蛋白通道的10倍。 (24:53) Clasp通过将C++和Common Lisp两种语言编译为LLVM字节码并链接为单一模块,同时应用链接时内联和fastcc调用约定,实现了零开销的C++与Common Lisp互操作性。 (21:13)

Detailed notes — zh

## Background 该视频由欧洲 Lisp 研讨会(European Lisp Symposium)于 2016 年 5 月 30 日在 YouTube 发布,记录了美国天普大学化学系 Christian E. Schafmeister 教授在第九届欧洲 Lisp 研讨会(ELS 2016)上的报告。视频简介指出,CANDO 是一门专为大分子与纳米尺度材料快速原型设计及优化而构建的编译型领域特定语言,它扩展了基于 LLVM 的 Common Lisp 实现 Clasp,并原生集成了大量 C++ 分子计算库与超算并行能力。 ## TL;DR Schafmeister 教授分享了他因天然蛋白质柔性折叠极难预测而转向设计刚性梯状大分子的历程,并阐述了为何现有计算化学工具无法应对高达 10^160 构型空间的探索瓶颈。为此,他研发了结合 Clasp、LLVM 与 C++ 深度互操作的高性能编译型分子设计语言 CANDO,将化学拓扑与物理力场转化为一等公民对象。在现场演示中,他通过 Emacs SLIME 交互式环境展示了从 2D 分子图到 3D 能量最小化孔道结构的构建过程,并详细汇报了一种效能理论上超越现有反渗透技术 1000 倍、通量远超天然水通道蛋白的人工海水淡化超级过滤膜设计及其物理机理。 ## Atmosphere & style 演讲兼具硬核编译系统黑客的技术极客感与前沿纳米化学家的宏大雄心,现场氛围轻松而充满智慧火花。Schafmeister 语言幽默生动,既有将蛋白质戏称为“如果冻般的分子铁锚”、将 Python 封装重型引擎调侃为“在驴背后绑喷气发动机”的诙谐自嘲,又有直言该研究可能“推迟人类文明崩溃”时的绝对庄重与自信。在 Emacs 终端中断运算并直接展示回溯调试时,展现出高超的即兴把控力,令台下的 Lisp 极客们不仅沉浸在跨语言底层架构的精妙设计中,更被宏观物理材料落地的颠覆性前景深深震撼。 ## Bulletin - [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) Christian Schafmeister 开发了编译型领域特定语言 CANDO,该语言建立在基于 LLVM 的 Common Lisp 实现 Clasp 之上,旨在解决大型刚性梯状大分子的计算机辅助设计与模拟瓶颈。 - [19:35](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1175s) Schafmeister 展示了受水通道蛋白启发的仿生纳米过滤膜设计,仅需 5 克材料铺展面积即可达标准足球场大小,且水通量理论上比天然水通道蛋白高出一个数量级。 - [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) 通过让 Clasp 将 Common Lisp 与 C++ 代码分别编译为 LLVM IR 并在链接期进行全程序优化,系统实现了无开销的跨语言内联与寄存器级快速调用(fastcc)。 - [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) 该纳米过滤膜依靠离子的水化层脱除能量惩罚实现高选择性脱盐,仅需约 8.2 米天然水柱重力压头即可驱动,理论效率比现有商业反渗透膜高出 1000 倍。 ## Key takeaways - [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) 天然蛋白质具有柔性单键折叠与易热变性的弱点,工程设计极难精确预测;转用成对化学键锁定的刚性梯状分子能提供确定性的三维空间几何构型。 - [01:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=113s) 实验室成功合成了模拟乙酰胆碱酯酶的刚性微型分子,将反应速率显著提升数千倍,证明通过刚性骨架定位催化基团可以实现高效仿生催化。 - [01:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=113s) 大型分子设计的候选空间高达 10^60 到 10^160 种构型,传统穷举虚拟库筛选失效,必须依托蒙特卡洛算法进行紧凑高频的突变评估。 - [01:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=113s) 通用软件重构频繁且胶水代码繁琐,分子设计领域急需一门能够像 Mathematica 改变物理数学一样的一体化编译型专用编程语言。 - [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) CANDO 继承自基于 LLVM 的 Clasp 编译器,将 239 个原生 C++ 分子类作为一等公民对象注入 Common Lisp 环境,并依托自动垃圾回收管理环状分子图拓扑。 - [09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) 系统内部完整实现了分子片段正则匹配(SMARTS)与符号求导引擎,可由 LLVM 直接生成原生高性能代码,以同时计算能量目标函数及其一阶和二阶导数。 - [09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) 直接通过高级动态语言封装 C++ 科学计算库(如 OpenMM、图形渲染、分子对接)可以兼顾开发灵活性与底层计算性能,避免了 Python 绑定的性能瓶颈。 - [10:52](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=652s) CANDO 支持从 ChemDraw 导入 2D 草图、设置手性立体化学、随机赋予初值,并通过最速下降法、共轭梯度法与截断牛顿-拉夫森法将千原子结构优化为物理合理的三维空间孔道。 - [15:57](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=957s) 基于水通道蛋白机制设计的人工纳米过滤膜在理论上比现有商业反渗透膜效率高出 1000 倍,且该设计已获得美国陆军工兵部队的资助。 - [15:57](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=957s) 得益于 Clasp 生成的原生机器码性能,研究人员能够直接在 Common Lisp REPL 中高效率执行大规模水分子盒裁剪与几何边界测试。 - [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Clasp 通过将 C++ 与 Common Lisp 统一编译为 LLVM IR 并在链接期进行 Pass 优化,将跨语言调用深度内联或转为 fastcc,消除了两种语言交互的运行开销。 - [23:27](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1407s) CANDO 的核心目标不是替代 NAMD 等分子动力学求解器,而是自动化构建数以百万计的结构变体,以便在数万核超算上实现超大规模并行筛选。 - [24:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1493s) 动力学轨迹追踪表明,人工纳米孔道的水通量比天然水通道蛋白高出整整 10 倍,其孔径尺寸的精确调控直接决定了水分子能否顺利透入。 - [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) 海水淡化通过狭窄孔径迫使钠氯离子脱去水化层产生极高能量惩罚,从而在错流流动模式下实现彻底的离子物理阻隔。 - [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) 相比体外仅能存活数小时至数天的柔软天然蛋白质,人工刚性双环骨架具有极强的物理化学耐用性,有望彻底替代脆弱且高能耗的传统工业反渗透膜。 ## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) 蛋白质设计的困境与刚性梯状分子设想 Christian E. Schafmeister 从免疫系统中的抗体与细胞膜通道切入,指出生物体内存在各种高度特化的分子机器:抗体会针对外来病毒演化出特定的结合口袋,膜通道则精细地控制分子进出细胞。他早年从事生物物理与蛋白质设计,曾尝试通过纸上设计、基因合成、导入细菌表达及结晶,制备出了最早的人工大型蛋白质之一。然而那次经历让他深受挫折——耗时整整四年做出来的分子犹如一个“分子铁锚”(molecular boat anchor),且根本无法总结出通用规律来复制成功。Schafmeister 坦言:“蛋白质非常难以处理,它们是软绵绵、果冻一样的东西,根本不是拿来做工程设计的理想材料。”(“proteins are horrible to work with they are soft squishy Jell-O like things that they're just not good materials to try and design with that was my problem with it”) 天然蛋白质在生命温和环境下表现惊艳——把一堆蛋白质放在 38 摄氏度下一个月,可以孕育出鹰、人类或树木;但一旦让它们脱离舒适区哪怕几分钟,就会变成“美味但毫无功能的东西”(例如煮熟的蛋)。为解决这一问题,Schafmeister 在十三四年前提出了一种替代构想:放弃通过柔性单键连接、折叠构象极难预测的传统多肽链,转而采用环状分子作为构建块(building blocks),并通过成对的化学键将它们相互锁死。这种连接方式形成了刚性的梯状分子(ladder molecules)。通过在梯状骨架的外侧悬挂功能基团并将多段骨架拼接,研究人员可以在分子内部构建出能够容纳并催化其他分子的口袋,以完全不同于天然蛋白质的刚性机制实现类似的功能。 ```mermaid flowchart TD accTitle: 天然蛋白质与刚性梯状分子的对比 accDescr: 对比柔性单键导致预测困难的蛋白质折叠与双键锁定刚性梯状骨架的设计路径 subgraph Protein ["传统天然蛋白质"] P1["柔性单键连接"] --> P2["复杂多肽链折叠"] P2 --> P3["折叠构象极难从头预测"] P3 --> P4["热稳定性差、脱离舒适区即变性"] end subgraph Ladder ["刚性梯状大分子 (Schafmeister 方案)"] L1["环状构建块 (Building Blocks)"] --> L2["成对化学键刚性锁定"] L2 --> L3["刚性梯状骨架 (Ladder Molecule)"] L3 --> L4["外侧悬挂功能基团构建活性口袋"] end ``` --- ### [01:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=113s) 仿生催化分子与指数级膨胀的设计空间 在验证这一概念的过程中,其实验室成功合成了一种能模拟乙酰胆碱酯酶(acetylcholinesterase)的刚性仿生分子。乙酰胆碱酯酶在人类神经系统中至关重要:在每次神经脉冲释放乙酰胆碱后,该酶会迅速将其水解失活,使突触为下一次信号传递做好准备;而有机磷神经毒剂正是通过阻断该酶导致神经系统锁死并致人死亡。由于获得了美国国防部(Department of Defense)的资助,Schafmeister 团队致力于制造能够解毒神经毒剂的催化剂。他们构建出的微型分子虽然比天然酶小得多,但只要三个催化基团被精确固定在三维几何构型中,就能在不消耗自身的前提下成千上万倍地加速化学反应:第一步反应速率提高了约 2500 倍,第二步提高了约 150 倍。尽管天然酶动辄能将反应加速数万亿倍(“那里面简直有魔法”,Schafmeister 赞叹道),但这证明了刚性骨架定位催化基团的可行性。 为了逼近天然酶的复杂催化能力,实验室必须将多个梯状片段拼接成拥有更多构型点的大型分子。然而,这带来了一个无法逾越的设计瓶颈——现有的计算化学软件根本无法应对这种设计需求。Schafmeister 曾反复重写专用工具,最初写了个带有图形界面的程序用来拼接单体,但学生们一旦在湿实验中开发出新的化学修饰方法,旧软件就彻底报废。他当时用 C++ 编写核心代码,再绑定到 Python 调用图形库,但在胶水代码和新化学机制的双重折磨下陷入了重构循环。 Schafmeister 意识到自己需要的不是一个孤立的应用程序,而是一门专属的领域语言:“我最终认定我需要的是一门语言,我需要一门能为分子设计所用的编程语言,就像 Mathematica 或 MATLAB 为数学或物理所做的那样。”(“I finally decided what I need is a language I need a programming language that works does for molecules what things like Mathematica mat lab does for mathematics or physics”)设计者需要扮演预言机(oracle)的角色:输入目标功能分子的几何空间约束,系统便能反算出可在实验室用几周时间合成出来的化学单体序列。 - 传统计算材料设计采用“穷举虚拟库筛选”模式,通过多层计算过滤器筛选小分子,但该方法对大型刚性大分子彻底失效。 - 目标大分子的可能构型空间高达 $10^{60}$ 到 $10^{160}$ 种分子,根本不可能生成初始候选集。 - 探索此类无法穷举的超大空间,必须使用蒙特卡洛(Monte Carlo)算法:从随机配置出发,在紧凑循环中进行随机突变以寻找局部最优解。 - 这种高频突变与评估要求紧凑的单核循环执行能力,催生了对专属编译型底层语言的需求。 --- ### [06:40](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=400s) CANDO 与 Clasp:基于 Common Lisp 与 C++ 的分子设计语言 为了高效运行蒙特卡洛搜索算法,Schafmeister 开发了名为 CANDO 的新型语言,其全称为“计算机辅助纳米结构设计与优化”(Computer-Aided Nanostructure Design and Optimization)。CANDO 并不是平地起高楼,而是构建在 Clasp 之上——Clasp 是 Schafmeister 此前开发的一个基于 LLVM 并能与 C++ 深度互操作的 Common Lisp 实现。他调侃道,Clasp 可能是世上现存的第 13 个 Common Lisp 实现,“这个世界大概不需要另一个 Common Lisp 实现了”,但之所以必须自己做,是因为没有任何现有的 Common Lisp 能满足高性能嵌入海量 C++ 分子库的需求。 ```mermaid flowchart TD accTitle: CANDO 语言架构层级 accDescr: 展示 CANDO 如何依托 Clasp、LLVM 及 C++ 类库构建分子设计环境 subgraph LLVM_Core ["底层编译器基础设施"] LLVM["LLVM 编译器后端"] end subgraph Clasp_Base ["Clasp (Common Lisp 实现)"] Clasp_CPP["150,000 行 C++ 核心代码"] ECL_Lisp["26,000 行 Common Lisp 代码 (源自 ECL)"] end subgraph CANDO_Ext ["CANDO (纳米结构设计语言)"] CANDO_CPP["155,000 行分子计算 C++ 代码"] CANDO_Classes["239 个 C++ 原生分子类<br/>(Atom, Bond, Residue, ForceField 等)"] CANDO_Lisp["扩展的 Common Lisp / CANDO 脚本层"] end LLVM_Core --> Clasp_Base Clasp_Base --> CANDO_Ext ``` 代码体量与系统构成细节如下: - **Clasp 底座:** 包含约 186,000 行代码,其中约 150,000 行为 C++ 代码,另有约 26,000 行 Common Lisp 基础代码来自 ECL(Embeddable Common Lisp)。 - **CANDO 增量:** 在 Clasp 之上额外增加了由 Schafmeister 编写的 155,000 行 C++ 源代码。 - **一等公民化学对象:** CANDO 为 Common Lisp 环境注入了 239 个原生的 C++ 类。原子(atoms)、分子(molecules)、化学键(bonds)、残基(residues)、手性构型(stereochemistry)以及力场参数(force field parameters)变得像 `fixnum`、`double` 或哈希表一样,成为受语言垃圾回收器(GC)直接管理的一等对象。 在功能层面上,分子在 CANDO 中被建模为单向有向图(nodes 为原子,edges 为化学键)。因为设计过程中需要成千上万次地构建新分子图并在评估后丢弃,系统必须依赖真正的自动垃圾回收,而不能使用引用计数(reference counting)——由于分子结构中环状拓扑(rings/loops)无处不在,引用计数会导致严重的内存泄漏。此外,CANDO 内置了分子力场引擎,支持针对复杂能量函数的非线性优化,并允许引入像 Maxima 这样的计算机代数工具自动生成并插入新的能量项微分方程。 ### [09:41](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=581s) CANDO 的底层能力与生态库集成 Christian E. Schafmeister 深入阐述了 CANDO 的核心计算机制。CANDO 能够在 Common Lisp 中直接执行符号求导(symbolic differentiation),随后生成执行速度极快的高效原生代码,用以同时计算能量目标函数及其一阶和二阶导数。系统还集成了立体化学(stereochemistry)处理以及自动原子类型分配(automatic type assignment)机制,虽然对于非化学背景的听众来说这些概念略显陌生,但它们是进行高精度分子能量计算的核心基石。此外,CANDO 实现了名为 SMARTS 的分子模式匹配语法,Schafmeister 将其形象地比喻为“分子片段的正则表达式”;通过在 Clasp / CANDO 内部完整重现 SMARTS,开发者能够以兼具高扩展性与极高运行速度的 Common Lisp 代码构建出极其强大的化学建模工具。 在架构拓展层面,Schafmeister 强调了与外部高性能科学计算库集成的必要性。以 OpenMM 为例,这是一个用 C++ 编写且包含极强大 C++ API 的分子建模引擎。业界通常将其封装为 Python 接口,但在 Schafmeister 看来,“they've exposed it to python but it's like putting a jet engine behind a donkey it's just horrible”(把这套引擎暴露给 Python 就像把喷气发动机绑在一头驴后面,糟糕透顶)。因此,他的目标是将 OpenMM、图形渲染库、电子结构计算库以及分子对接(docking)库等一系列重型 C++ 科学计算工具全方位接入 CANDO,直接在 Common Lisp 环境下驱动这些高性能底层资产。 ```mermaid flowchart TD accTitle: CANDO 核心架构与外部库集成 accDescr: 展示 CANDO 内部如何结合符号求导、SMARTS 正则与 C++ 底层库生成原生代码并进行能量计算。 subgraph CANDO_Core ["CANDO / Clasp 环境 (Common Lisp)"] direction TB SMARTS["SMARTS 模式匹配<br/>(分子正则表达式)"] SymDiff["符号求导系统<br/>(Symbolic Differentiation)"] CodeGen["LLVM 原生代码生成<br/>(函数 / 一阶导 / 二阶导)"] SymDiff --> CodeGen end subgraph External_Engines ["外部高性能 C++ 库集成"] direction TB OpenMM["OpenMM (分子动力学引擎)"] OtherLibs["图形库 / 分子对接 / 电子结构计算"] end CANDO_Core <-->|"C++ 模板与原生绑定"| External_Engines ``` ### [10:52](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=652s) 拯救人类文明的项目:从 ChemDraw 到三维能量最小化 Schafmeister 抛出了一个极具雄心的测试案例:一种可能“推迟人类文明崩溃,为解决其他生态危机争取时间”的新型净水过滤膜分子设计。他半开玩笑又极其认真地强调:“you heard me right I think this is really really important project”,并透露该研究已获得美国陆军工兵部队(Army Corps of Engineers)的科研经费资助。他在现场启动了基于 Emacs 的 SLIME 开发环境,展示通过 Common Lisp 驱动 CANDO 运行的完整实时 Demo。 ```mermaid flowchart LR accTitle: 2D 分子图到 3D 能量最小化结构的生成流程 accDescr: 描述从 ChemDraw 导入 XML 分子图、坐标随机化到非线性数值优化的全过程。 subgraph Input ["草图输入与解析"] CD["ChemDraw 绘制二维结构"] -->|"导出 XML"| CANDO_XML["CANDO 加载为分子图结构<br/>(所有原子处于原点 0,0,0)"] end subgraph Geometry ["几何与立体化学设定"] CANDO_XML --> Stereo["手动/自动设定手性中心<br/>(R/S Stereochemistry)"] Stereo --> RandCoord["分配随机三维坐标<br/>(约 1000 个原子)"] end subgraph Opt ["C++ 能量最小化求解器"] RandCoord --> Min["非线性优化<br/>(最速下降法 -> 共轭梯度法 -> 截断牛顿法)"] Min --> Target3D["物理合理的 3D 分子孔道结构"] end ``` 在具体的建模流程中,Schafmeister 首先使用化学领域的“Adobe Illustrator”——ChemDraw 绘制分子的二维拓扑草图,导出为 XML 文件并载入 CANDO。刚载入时,这个包含约 1000 个原子的复杂分子图完全没有空间三维坐标,全部塌缩在原点 `(0, 0, 0)`。系统首先允许配置每个碳原子的手性立体化学(R 或 S 构型),随后为原子随机赋予空间初值。为了将杂乱的初始点转变成符合化学物理规律的三维结构,CANDO 调用以 C++ 实现的能量最小化求解器:化学键被建模为具有固定目标长度和张力的弹簧,键角同样被约束为角度弹簧;随后,算法依次使用最速下降法(steepest descent)、共轭梯度法(conjugate gradients)以及截断牛顿-拉夫森法(truncated Newton-Raphson minimizer),依靠 LLVM 生成的导数求值代码执行非线性优化。由于现场演示运算耗时较长,Schafmeister 在终端直接按下 `Ctrl+C` 中断计算,顺势向观众展示了 SLIME 完备的断点回溯(backtrace)、参数检查等强大的交互式调试功能。 - 初始化逻辑依赖 ASDF 系统加载,支持角度转弧度、三维点阵晶胞(unit cell)构建等大量底层数学与宏定义工具。 - 体系内包含约 1000 个原子,优化过程通过能量泛函求解迫使分子逐步满足全部几何拓扑约束。 ### [15:57](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=957s) 水通道蛋白模拟:二维膜排布与水分子切割 Schafmeister 展示了优化生成的单通道分子构型。其设计灵感来源于人体肾脏中维持细胞膜渗透压平衡的水通道蛋白(Aquaporin)——一种近乎完美、除水分子外任何溶质都无法透过的生物通道。他指出加利福尼亚州正在建造庞大的反渗透(Reverse Osmosis)海水淡化厂,而眼前这款纳米通道在理论效率上可比现有的商业反渗透膜高出整整 1000 倍。为了在分子动力学引擎中验证其效能,单个水通道必须在二维平面上平铺阵列化并构筑成过滤膜,并在其两侧填充水分子环境。 在生成周围的水盒子(water box)时,Schafmeister 演示了一项令他振奋的技术突破:系统需要将四个预生成的水分子箱像贴瓷砖一样拼接起来包覆整张滤膜,并精准裁剪掉与膜体空间重叠或落在包围盒(bounding box)之外的水分子。过去,这种涉及数以万计水分子的大规模几何测试(`molecule-in-box`),他绝对不敢在 C++ 之外的任何语言中尝试;但在如今的 CANDO / Clasp 环境下,直接用 Common Lisp 编写的测试与过滤逻辑已经拥有足够的原生性能,能够流畅地在 REPL 中边调试边高效剔除多余水分子,从而迅速裁切出上下对称的水层以供膜结构嵌入。 ### [19:35](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1175s) 模拟结果与超级过滤膜的物理极限 当模型设置完毕并交付分子动力学(Molecular Dynamics)模拟运行后,Schafmeister 向观众展示了耗费多台计算设备连续运算数天、模拟时长仅数纳秒(nanoseconds)的微观流动结果。在剔除了上下表面的大体积背景水分子后,画面清晰展示出水分子高速穿梭进入膜内纳米空腔的动态细节。模拟结果显示,由于通道内部的阻力极低,只要施加微小的压差,水分子就能形成持续定向流动。 基于这套模拟结构计算出的工程宏观指标令人惊叹: - 仅需 5 克该设计材料(用手掌即可托起),铺展开来的膜表面积就能达到一个标准足球场(soccer pitch)大小。 - 膜表面约三分之一的面积是供水自由通过的有效物理开孔,相当于一条截面积达三分之一足球场大小的宏观输水管道,足以供给整座城市的日常用水。 - 传统反渗透技术需要极高的机械加压,而该纳米膜无需严苛的高压驱动,仅仅依赖 27 英尺(约 8.2 米)高的天然水柱重力压头即可顺畅滤水。 面对全场的掌声,Schafmeister 总结道:“theoretically there's no way in this universe to make a better membrane than this and this could be used to purify anything water all sorts of things”(从理论物理极限来看,这个宇宙里不可能做出比这更完美的过滤膜了;它不仅可用于水净化,还能用于分离提纯各种物质)。虽然目前它仍是一个纯理论设计的纳米材料模型,但其实验室正全力筹集研发资金,计划将这套由 CANDO 设计的宏观分子结构真正合成落地并进行实体物理检验。 ### [21:13](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1273s) Clasp 与 LLVM 深度整合:跨越 Lisp 与 C++ 的零开销调用 Christian Schafmeister 坦言,展示中的分子模拟运行仅仅是在大约四周前才刚刚完成的。在埋头钻研 Common Lisp 底层基础设施整整几年之后,他终于让系统运行得足够快,重新恢复了构建复杂三维分子的能力。更关键的技术突破发生在演讲前的最后两周:Clasp 作为基于 C++ 和 LLVM 构建的 Common Lisp 实现,实现了一种颠覆性的全程序跨语言优化机制。Schafmeister 发现,可以将 C++ 源码编译为 LLVM 中间表示(IR),同时把 Common Lisp 代码也编译为 LLVM IR,随后将两者链接在一起运行 LLVM 优化 pass。 ```mermaid flowchart TD accTitle: Clasp LLVM 跨语言全程序优化流程 accDescr: 展示 C++ 与 Common Lisp 源码分别编译为 LLVM IR,链接后通过内联与 fastcc 实现零开销调用的架构流程。 subgraph Source["源码输入"] CPP["C++ 源码<br/>(含 CL_DEFUN 标注)"] CL["Common Lisp 源码"] end subgraph Compile["LLVM IR 编译与链接"] CPP -->|"Clang 编译"| CIR["C++ LLVM IR"] CL -->|"Clasp 编译"| LIR["Lisp LLVM IR"] CIR --> LINK["LLVM 链接器"] LIR --> LINK end subgraph Opt["全局代码生成"] LINK --> PASS["LLVM 优化 Passes"] PASS -->|"合理小函数"| INL["全程序深度内联"] PASS -->|"大函数"| FCC["fastcc 快速调用约定<br/>(寄存器级参数传递)"] INL --> BIN["无开销本地机器码"] FCC --> BIN end ``` 这种机制打破了高级动态语言与底层系统语言之间的性能藩篱。Schafmeister 指出,在这种全程序优化下,任何合理的调用都会被彻底内联;而对于体积过大、不适合内联的函数,则会自动提升为快速调用约定(`fastcc`,即 Fast Calling Convention),直接利用 CPU 寄存器传递参数与匹配状态。这彻底抹平了跨语言通信的开销。在接口导出方面,Clasp 的自动化刮取工具(Scraper)极大地减轻了开发负担:开发者只需在 C++ 函数前加上 `CL_DEFUN` 宏,刮取器便会自动扫描解析并生成接口包装,无缝暴露给 Common Lisp 环境,整个 Clasp 中数以千计的底层 C++ 函数正是以此种方式优雅暴露给运行时的。 - “Basically I can hook into C++ code with no overhead compared to C++ talking to C++.”(Schafmeister 强调跨语言调用的零开销特性) - “All of Clasp is exposed that way; there's thousands of functions that are exposed that way.”(Schafmeister 说明自动化宏刮取工具在系统中的普遍应用) --- ### [23:27](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1407s) 分子动力学模拟与超大规模并行筛选 进入现场提问环节,参会者对水通道模拟的具体运作机制表现出浓厚兴趣。Schafmeister 解释道,在实际模拟中,研究人员会在膜两侧的水相区域加入特定离子,随后启动分子动力学(MD)计算。这种模拟通过计算原子间的作用力,推动原子发生极其微小的位移,然后再重新计算作用力。虽然 NAMD 等专业分子动力学引擎在这类物理模拟上表现出色,但这类计算在时间尺度上极其昂贵,“极其缓慢,需要耗费数天计算时间才能模拟出几个纳秒的动态过程”。 Schafmeister 强调,CANDO 的核心使命并非重新发明分子动力学求解器,而是解决上游的“高通量设计与自动化构建”瓶颈。CANDO 编写的代码能够飞速且自动化地完成复杂微观计算环境的设置,并在周期性边界条件(Periodic Boundary Conditions)下生成数以百万计的结构变体设计。随后,这些任务被分发到超级计算机上成千上万个 CPU 核心上并行运行,并在模拟结束后自动解析评估,迅速筛选出性能卓越的人工纳米通道。 - “What I'm doing here is I've got all the code to set up the calculations very quickly and efficiently, but set them up in a way where I can make millions of different variants of them and run these simulations on hundreds of thousands of CPUs in parallel and then automatically evaluate them and figure out which channels are working better than other.”(Schafmeister 阐述 CANDO 结合超算进行大规模并行纳米材料筛选的架构思路) --- ### [24:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1493s) 水分子通量追踪与伊利诺伊大学合作 针对通道过滤性能的微观验证,Schafmeister 详细介绍了水分子运动轨迹的量化统计流程。通过分析周期性边界条件下的模拟轨迹,专用代码可以跟踪每一个独立的水分子,记录它们穿越膜通道的实际流向与频次,并以此近似估算该人工合成膜的整体水通量(Flux)。模拟结果显示,CANDO 设计的这种仿生大分子通道表现异常出色,其水通量甚至比天然水通道蛋白(Aquaporin)高出整整一个数量级,其行为特征基本上就像一个高效的分子筛。 在微观结构参数微调方面,Schafmeister 指出通道内部空间的松紧度必须精准调控:如果分子间充填过于致密,水分子根本无法顺利钻入通道内部,甚至会出现刚进入端口便被瞬间弹飞回水相的现象。谈及具体的高强度动力学模拟工作时,Schafmeister 笑着透露这些计算主要是由他在伊利诺伊大学(University of Illinois)的紧密合作伙伴完成的——对方实验室长期深耕水通道蛋白的高精度模拟,在微观流动机制分析上拥有深厚积淀。 - “And the flux that we get is 10 times higher than our aquaporin; this thing is basically acting like a sieve.”(Schafmeister 赞叹人工合成通道的渗透通量远超天然蛋白质通道) --- ### [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) 海水淡化机制、离子阻隔与膜材料的工程耐用性 当有观众追问该结构如何阻挡大于水分子的杂质(例如离子)时,Schafmeister 将话题引入到海水淡化的核心机理:海水本质上是溶解了氯化钠(NaCl)的水溶液,溶液中的钠离子($\text{Na}^+$)和氯离子($\text{Cl}^-$)外层紧密包裹着一层由水分子构成的“水化层”(Hydration Shell)。如果离子要穿过通道,就必须强行脱去这层水化外壳。只要将通道狭窄处的物理孔径设计得足够紧凑,离子脱去水化层的能量惩罚(Free Energy Penalty)就会变得不可逾越,从而被完全阻隔在膜的一侧。 在工程应用形式上,这种膜不能作为直接强推流体的死端过滤(Dead-end Filtration)使用,而必须采用逆流/错流(Countercurrent / Cross-flow)流道设计。高盐海水在膜表面流过,纯水透过膜孔被收集,截留下来的离子在原水侧持续富集形成浓缩卤水(Brine)并被冲刷排出。在讨论膜材料的使用寿命时,Schafmeister 对这种刚性大分子结构充满信心。天然水通道蛋白由柔软易变的蛋白质构成,极易因热变性或化学环境失活,在体外通常只能维持数小时到数天的寿命;而基于双环双氨基酸构建的人工骨架异常坚固,使用寿命将长得多。面对膜污染(Fouling)与定期反洗(Back-flushing)等传统工程问题,他直言现有的反渗透(RO)膜技术不仅原始而且容易损坏,而人工合成的大分子纳米膜将带来根本性的性能跃升。 - “If a sodium chlorine ion is going to fit through there, you have to strip those waters off; so if you make the constriction tight enough, then the penalty to strip those waters off is too high for it to get through.”(Schafmeister 解释水化层能量惩罚如何实现离子的高选择性拦截) - “I think they could be a very, very long time; our aquaporins have lifetimes in the order of hours to days because they are made out of scrambled [protein], but we constantly recycle them; these things are much more robust.”(Schafmeister 对比人工通道与天然水通道蛋白在机械与物理稳定性上的天壤之别) - “I mean [reverse osmosis] membranes are just terrible technology; they're just the best [we have].”(Schafmeister 直截了当地批判现有工业反渗透技术的局限性与改进空间) ## Notable quotes > [26:21](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=1581s) reverse osmosis membranes are just terrible technology; they're just the best [we have]. — Christian E. Schafmeister > [00:00](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=0s) proteins are horrible to work with they are soft squishy Jell-O like things that they're just not good materials to try and design with that was my problem with it — Christian E. Schafmeister > [01:53](https://www.youtube.com/watch?v=5bQhGS8V6dQ&t=113s) I finally decided what I need is a language I need a programming language that works does for molecules what things like Mathematica mat lab does for mathematics or physics — Christian E. Schafmeister ## Mentioned CANDO, Clasp, Christian E. Schafmeister, Common Lisp, LLVM, C++, Python, OpenMM, ChemDraw, Emacs, SLIME, ECL, Maxima, NAMD, 美国国防部, 美国陆军工兵部队, 坦普尔大学, 伊利诺伊大学, 乙酰胆碱酯酶, 水通道蛋白, 反渗透 ## Video description ELS 2016, 9th European Lisp Symposium, 9-10 May 2016, Department of Computer Science, AGH University of Science and Technology, Kraków, Poland. Christian E. Schafmeister, Chemistry Department, Temple University, 1901 N. 13th Street Philadelphia, PA. CANDO is a compiled programming language designed for rapid prototyping and design of macromolecules and nano- meter-scale materials. CANDO provides functionality to write programs that assemble atoms and residues into new molecules and construct three-dimensional coordinates for them. CANDO also provides functionality for searching molecules for substructures, automatically assigning atom types, identifying rings, carrying out conformational search- ing, and automatically determining stereochemistry, among other things. CANDO extends the Clasp implementation of the dynamic language Common Lisp. CANDO provides classes for representing atoms, residues, molecules and ag- gregates (collections of molecules) as primitive objects that are implemented in C++ and subject to automatic memory management, like every other object within the language. CANDO inherits all of the capabilities of Clasp, including the easy incorporation of C++ libraries using a C++ tem- plate programming library. This automatically builds wrap- per code to expose the C++ functionality to the CANDO Common Lisp environment and the use of the LLVM li- brary[1] to generate fast native code. A version of CANDO can be built that incorporates the Open Message Passing Interface C++ library[2], which allows CANDO to be run on supercomputers, in order to automatically setup, start, and analyze molecular mechanics simulations on large par- allel computers. CANDO is currently available under the LGPL 2.0 license. [Source](https://www.youtube.com/watch?v=5bQhGS8V6dQ)

Source quotes

[26:21] Christian E. Schafmeister: reverse osmosis membranes are just terrible technology; they're just the best [we have]. [0:00] Christian E. Schafmeister: proteins are horrible to work with they are soft squishy Jell-O like things that they're just not good materials to try and design with that was my problem with it [1:53] Christian E. Schafmeister: I finally decided what I need is a language I need a programming language that works does for molecules what things like Mathematica mat lab does for mathematics or physics

Source quotes

[2:04] Christian Schafmeister: I need a programming language that does for molecules what things like Mathematica or MATLAB does for mathematics or physics. [26:21] Christian Schafmeister: Reverse osmosis membranes are just terrible technology; they're just the best we have. [21:13] Christian Schafmeister: Basically I can hook into C++ code with no overhead compared to C++ talking to C++.

Original transcript

[0:00] are we all [0:01] set anything going to happen Okay uh we [0:04] also make these things they're [0:05] antibodies they're part of our immune [0:07] system uh they have this little pocket [0:08] here that binds different proteins you [0:10] know you get infected with a virus and [0:12] these things start to evolve in order to [0:15] bind uh proteins of viruses these things [0:18] are interesting they're membrane [0:20] channels that let things from the [0:21] outside cells into cells and vice versa [0:24] and um these are very important for for [0:27] purifying molecules I'd like to be able [0:29] to make all these kind kind of things [0:30] and I started out in biophysics I did [0:33] protein design I made one of the first [0:34] unnatural large proteins by designing it [0:37] on paper designing the gene sticking to [0:40] bacteria expressing it crystallizing it [0:43] but the thing was a molecular bow anchor [0:45] to be four years to make it and I didn't [0:47] know how to make another one because [0:49] proteins are horrible to work with they [0:50] are soft squishy Jell-O like things that [0:53] they're just not good materials to try [0:55] and design with that was my uh my [0:58] problem with it so you can make [1:00] wonderfully functional things you know [1:02] take a bunch of proteins hold them at 38 [1:03] degrees for a month and you'll get [1:05] wonderful things like eagles and us and [1:07] trees but if you take them out of their [1:09] comfort zone even for a few minutes they [1:11] turn into uh something that's delicious [1:13] but not very functional I I use this [1:16] last year um so this is what I came up [1:19] with is what if we make building blocks [1:20] that don't link together through a [1:22] single Bond where they're flexible and [1:24] have to make these large chains that [1:25] then have to fold and that folding [1:27] process is very difficult to predict why [1:29] don't we we make proteins out why don't [1:31] we make things like proteins but make [1:32] them out of building blocks that are [1:33] rings and Link together through pairs of [1:35] bonds so you make stiff lad [1:39] molecules and then by hanging groups off [1:41] of these latter molecules and by putting [1:43] a bunch of these together I can make [1:45] molecules that have pockets inside of [1:46] them that can operate on other molecules [1:49] and they can do all the things the [1:50] proteins do but do it in a completely [1:51] different [1:53] way um and we've been doing this I I [1:56] invented this about 133 14 years ago [1:59] you've been making molecules figure out [2:01] how to synthesize the building blocks [2:02] make the molecules make molecules that [2:04] do things this is one that mimics an [2:07] enzyme called acetycholine estray that's [2:09] in our brain that hydrolyzes [2:11] acetycholine the Nur neurotransmitter [2:14] between every neural pulse you dump out [2:16] all this acetycholine then there's this [2:18] fantastic enzyme called acetycholine [2:20] esteras that goes in reacts it with [2:23] water deactivates it so now the synapse [2:26] is ready for the next thought to come [2:28] through and if you get in if you get [2:30] exposed to organophosphorous nerve [2:32] agents for instance they go in there Jam [2:34] that protein and fuse your your nervous [2:36] system that's why nerve agents kill us [2:38] so effectively so we've got money from [2:41] we had money from the Department of Def [2:43] defense to understand this thing to try [2:45] and make cets like this and especially [2:47] to try and make molecules that can [2:49] detoxify nerve [2:51] agents um this this little simple [2:54] molecule is much smaller and simpler [2:55] than an enzyme but it does what an [2:57] enzyme does you put in starting [2:59] materials convert it to products and [3:01] this is time on the axis here this is [3:03] how much product is being generated and [3:05] when we hold all of these three groups [3:07] in just the right threedimensional [3:09] constellation this [3:11] constellation then they can convert the [3:13] starting material into the product [3:15] without themselves being consumed and [3:16] they speed up the reactions or two of [3:18] them they speed the first one up about [3:20] 2500 fold and the second one up about [3:22] 150 F now the enzymes in our body speed [3:25] things up trillions of [3:28] fold there's wizard going on in here uh [3:31] and we haven't achieved that yet but [3:33] these are very tiny and so I need to [3:34] make larger things to do the sorts of [3:36] things that our enzymes to so what we're [3:40] doing now is we're starting to link [3:43] these segments together to create big [3:45] molecules that have many many points of [3:48] configuration and now we have an [3:51] enormous design problem designing [3:53] something like this to catalyze a [3:55] particular reaction or act as a membrane [3:57] channel is an enormous design challenge [3:59] and the software tools to do this don't [4:01] exist that's why I'm [4:03] writing and I've written it a couple of [4:05] times and I would write a program that [4:07] sort of give you a graphical user [4:09] interface to stitch together our [4:10] building blocks and then my students [4:12] would come up with some chemistry that [4:13] would let us put more stuff on it but it [4:15] wouldn't work with my old software and I [4:17] was writing all the C++ code and then [4:19] hooking it into Python and then using [4:21] python libraries to do you know the [4:23] graphics and um I was it was driving me [4:27] crazy trying all this stuff together and [4:30] and then you know they come up with new [4:31] chemistry and I have to throw it away [4:33] and start over again and and it's just a [4:35] nightmare so I finally decided what I [4:37] need is a language I need a programming [4:39] language that works does for molecules [4:41] what things like Mathematica mat lab [4:43] does for mathematics or [4:45] physics um right because I want to you [4:48] know I want to build things like where I [4:50] take multiple segments multiple segments [4:52] like these guys tie them together and [4:54] create pockets and and I want to design [4:57] them so I need an oracle that can help [4:59] me design these molecules something [5:01] where I can give the requirements of a [5:03] functional molecule and I know what that [5:05] means as a chemist I know where groups [5:06] need to be in space so I need a [5:08] scaffolding behind it to hold those [5:10] groups in place um but I need some sort [5:12] of software that will take a functional [5:15] the requirements of a functional [5:17] molecule and give me a sequence that my [5:19] students then can go in the lab and make [5:20] in a couple of [5:22] weeks we could do this we could solve I [5:24] think all of the world's [5:26] problems um so a lot of people are doing [5:29] computation materials designed and they [5:31] take this sort of approach where they'll [5:32] build a large sort virtual library of [5:35] molecules and then run them through a [5:37] series of successive sort of [5:39] computational filters until they come [5:42] down with a small set that may do what [5:44] they want and then they'll go and buy [5:45] those compounds when try and make them [5:47] to see if they're active for something [5:50] of this that works with small sorts of [5:52] molecules like the ones we've made up [5:53] until now but for these larger ones [5:55] that's not going to work the space here [5:57] is just too huge I mean we're talking [5:59] about 10 to the 60th the 10 to the 160th [6:02] molecules of this size that I could make [6:06] uh no way you can you can even build a [6:09] starting Set uh so the way to do it is [6:12] to start with a random configuration and [6:15] then use Monte Carlo you know when you [6:17] want to search a very large space that [6:18] is just completely intractable to search [6:20] exhaustively you start at one point and [6:22] then you randomly mutate you try and [6:24] find local optimal and that is that is [6:27] proven again and again to work for for [6:29] large search problems but that requires [6:32] a very different set of software tools [6:34] and really requires a language because [6:36] you need to run a mon Carlo Loop in a [6:38] very tight Loop in One [6:40] processor and so I've designed a new [6:43] language for that it's called can do and [6:45] it stands for computerated Nan structure [6:47] design and optimization and what it does [6:49] is it runs it extends clasp so clasp is [6:52] the common list that I told you that I [6:53] was implementing the last year and I've [6:55] been continuing to develop it of course [6:57] it's the foundation of can do so clasp [7:00] is a is common list it is a Implement [7:02] it's a 13th sort of implementation of [7:05] common list that's probably still [7:07] running right now I know the world [7:09] doesn't need another probably doesn't [7:10] need another implementation problem this [7:12] this one's interesting because it [7:13] interoperates with C++ and it's based on [7:16] llvm so that's new about it but you know [7:19] doesn't really need it what I do need is [7:21] something to rest this on and that [7:22] wasn't going to work on any other common [7:24] list that exists right now because I [7:25] need C++ integration there's lots of C++ [7:28] libraries I need toe into I'm not going [7:30] to rewrite so I need to tie into them [7:33] efficiently so that's what I've devel [7:36] developed can do okay so what is it so [7:39] uh clasp is a common list implementation [7:43] can do ads 155,000 lines of C++ source [7:47] code that I wrote to clap [7:50] 186,000 Source lines of code which [7:53] consists of about 150,000 lines of C+ [7:56] plus and 26,000 lines of uh [7:59] common list code that I stole from ECA [8:03] thanks [8:05] um what can do does is extends class by [8:09] adding 239 C++ classes that become first [8:12] class built-in objects within common [8:14] list you know just like fix num or [8:17] double or hash tables I got atoms now [8:19] and I got molecules and I got conal prog [8:22] stereochemistry and I've got force field [8:23] parameters and force fields got all [8:25] sorts of chemistry stuff in there that's [8:27] first class memory men garbage collected [8:30] classes built-in [8:32] C++ um so they're very pretty [8:36] efficient uh right it gives you atoms [8:38] bonds all sorts of stuff that uh [8:40] chemistry needs and it's all managed by [8:42] the GC and can do is also now a growing [8:46] body of common list code that uses all [8:49] this stuff I mean it technically it's [8:51] not common list it's a superet of common [8:53] list in principle though we could Port [8:55] all the stuff back to other common lists [8:57] now but it's can do common l [9:00] source code that's extending this thing [9:02] okay so what can it do it can represent [9:04] molecular [9:05] structures molecules are graphs they're [9:07] like atoms or nodes they point to each [9:10] other that's bonds so you get this uh [9:14] unidirectional graph um I want to be [9:16] able to build those things and then [9:17] throw them away so I need them to be [9:19] garbage collect I can't use reference [9:21] counting because I have loops all over [9:22] the place and they'll stick around so I [9:25] need a serious real garbage [9:27] collector um can do has built-in force [9:30] field so it's got nonlinear optimization [9:32] of energy functions complex energy [9:34] functions I need to be able to put new [9:36] energy terms into it so I'd like to use [9:38] things like Maxima to different generate [9:41] symbolic diff do different symbolic [9:44] differentiation in common list and then [9:45] generate fast native code to to evaluate [9:50] the function the first derivative and [9:51] the second derivative I do that [9:53] now um it's got things like automatic [9:56] type assignment that probably doesn't [9:57] mean much to people here but it's it's a [10:00] way of doing uh these energy [10:02] calculations it go about stereochemistry [10:04] it's got something like regular [10:06] expressions for molecular fragments it's [10:08] called smarts I didn't invent this but [10:10] I've implemented it inside of clasp Com [10:13] or can do and um basically lets you [10:15] build really complex powerful chemistry [10:17] tools that run fast and scale in in in [10:21] can do common [10:22] list you can also tie in other libraries [10:25] so open mm is a molecular modeling [10:28] package written in C+ plus with a very [10:30] powerful C++ API they've exposed it to [10:33] python but it's like putting a jet [10:36] engine behind a donkey it's just [10:40] horrible um um and I want to tie all [10:42] these other sorts of libraries like [10:44] Graphics libraries and electronic [10:46] structure calculation libraries docking [10:48] libraries I want tie them into can do so [10:50] I can drive them from that [10:52] code okay so let me give you a little [10:54] test case okay this is a molecule here [10:57] this is a little thing that I'm I'm [10:58] working on right now that I think could [11:00] Pro you know with further development [11:02] could help save off the collapse of [11:04] human civilization so that we have time [11:06] to fix all of our other products you [11:09] heard me right I think this is really [11:10] really important project the idea is to [11:12] make perfect water filters right we've [11:14] got funding enough from the Department [11:16] the Army Corps of Engineers to um [11:19] develop these things let me show you [11:20] what I'm talking about here a little [11:23] live demo here scaled bring this up here [11:30] bring this out [11:33] here right so see that there [11:37] gles all right so um this is [11:42] uh let me just show you how fast this is [11:45] to start [11:46] up so this is [11:49] slime and [11:53] do all right so I'm starting up slime [11:56] now it's already compiled slime so it's [11:58] it's uh [12:01] pry quick okay there we are we got slime [12:04] up all right so what this is oh okay so [12:07] here we have at the top is the common [12:09] list source code the can do common list [12:11] source code that I've written to build [12:12] some alls right so this first is [12:15] initialization stuff so what it does is [12:16] setting directories it's requiring it's [12:18] bringing in ASDF because of my my uh can [12:22] do common list code is AS ASDF systems [12:26] um so I just evaluate that bam it's [12:31] evaluated keep going [12:33] down okay here's a bunch of functions [12:35] that do things like uh uh maintain lines [12:39] and build unit cells and do conversions [12:41] from degrees into radians build unit [12:43] cells for uh for making uh [12:46] three-dimensional arrays of things um [12:50] just a bunch of functions all written [12:51] and can do common list that do a bunch [12:55] of housekeeping stuff for me [12:56] here and just there's a [13:01] macro um okay so I'm just going to [13:03] evaluate compile all these functions [13:06] here okay so they're compiled keep going [13:09] down set a directory but there's some [13:11] cool stuff coming in a second okay here [13:13] what I'm doing is I'm I I sketch a [13:15] molecule in a program called chemdraw [13:17] which lets me just like it's a it's the [13:19] program that chemists use to draw [13:20] molecules it's like a it's like a you [13:23] know Adobe Illustrator but for molecules [13:25] so we sketch a molecule in there and I [13:28] can write it out as a XML file from [13:30] chemdraw and so candu can load this XML [13:34] file and it builds a graph of the [13:35] molecule but it doesn't have any [13:37] threedimensional [13:38] coordinates or [13:40] anything um I can set a thing called [13:43] stereochemistry every carbon can have [13:45] like what's called s or R sterochemistry [13:47] it's two different threedimensional [13:49] Arrangements of groups around it [13:51] chemistry concept so I can set those [13:53] here um and then what I'm going to do is [13:56] build a threedimensional structure of [13:58] this Mo let me show you that words here [14:02] so I'm going to set up all the energy [14:03] calculation stuff that's done I'm going [14:06] to here's okay so here's what I start [14:09] with there's probably about a thousand [14:11] atoms in this molecule I have no [14:13] structural information at all so they [14:15] all start out at z00 Z this a [14:17] threedimensional object all these atoms [14:18] are at the same point in [14:20] space [14:23] um to get started I just assign random [14:27] coordinates and there's my molecule to [14:30] start with okay uh to get a reasonable [14:35] three-dimensional structure I use what's [14:37] called Energy minimization basically [14:39] describes all the chemical bonds as [14:41] Springs that have to be a certain length [14:43] and they've got a certain tension to [14:45] them Bond angles where you got atom atom [14:47] atom those are also Springs and they [14:50] they control the angle and all of that [14:54] chemistry knowledge is built now into [14:56] the structure of this thing that I [14:57] loaded and and um what I'm doing here is [15:00] a nonlinear optimization that minimizes [15:02] the energy by moving the atoms in order [15:04] to get all the restraints satisfied as [15:07] well as possible so this is written in [15:10] C++ and this is using steepest descent [15:13] conjugate gradients and then a trunk M [15:15] rafts and U [15:18] minimizer um using energy functions that [15:20] I calculate the derivative of and then I [15:23] use code generation in order to generate [15:25] efficient code to evaluate those [15:27] functions so it runs pretty quick but [15:29] it's going to take a little while to [15:31] minimize so I'm just G to contr C okay [15:34] so we have SLB up [15:36] here um I just control SE it so I can [15:39] look you know I can go in and look at [15:41] the back trace and look at arguments and [15:42] functions it's just like you [15:45] know it's a pretty good debugger um can [15:50] quit out of that let's bring that there [15:53] okay so now um I want to see what I [15:57] built all right [16:00] so now this is a prototype for a water [16:02] Channel this is a prototype for a [16:04] molecule that it's like aquaporin in our [16:06] kidneys It's A protein that maintains [16:08] the osmotic balance across cell [16:09] membranes to keep them from bursting and [16:12] it is almost a perfect filter for water [16:14] it doesn't let anything else through [16:16] just water and um right now we're you [16:19] know in California they're building this [16:20] huge reverse osmosis M five minutes wow [16:24] okay they're building this huge reverse [16:26] osmosis plant in order to purify water [16:29] um this this thing could work a thousand [16:33] times more efficiently than this current [16:36] existing Technologies for reverse [16:38] osmosis memories but we have to first [16:41] demonstrate that computationally um so [16:44] what I this is just a prototype of one [16:47] channel the idea is water would come in [16:49] from here go down through here and then [16:51] come out the other side but I need to [16:53] pack these into a two-dimensional [16:54] membrane to start doing [16:56] simulation so um that that's [17:00] what I do here so I build a [17:03] two-dimensional array of these [17:05] things and then I put them up and [17:07] there's a two-dimensional [17:09] Ray now um simulation in water is [17:13] incomplete without water so let's go [17:16] down and get the [17:18] waters I'll skip the other stuff there [17:22] evaluate that get a water box okay so [17:26] here's what the water looks like [17:33] okay so this is a box of waters that [17:36] somebody box of waters that somebody [17:38] else generated that I need to pack [17:39] around this thing in order to set up for [17:42] simulation so um let's close [17:46] this um lost [17:51] here so I need to build [17:55] a I'm GNA not say as many words here I [17:59] need to build I I what I do is I tile [18:01] four of these boxes of water in order to [18:02] Encompass the entire membrane that I [18:04] built there uh close [18:08] that and start carving [18:12] out [18:16] pieces so I'm just evaluating this stuff [18:18] in slime here um okay this is [18:21] interesting so these two functions here [18:22] molecule in a box what that determines [18:24] is I build a b bounding box which is a [18:27] CLA class that describes pounds of a box [18:30] and then I have all these water this [18:31] huge number of water molecules what the [18:34] molecule in a in a Bo in box function [18:36] does is it just tests the water to see [18:38] if it's inside a box or not inside the [18:40] box I don't want to do this stuff in C++ [18:43] I nor couple of months ago I would have [18:45] never thought to do it anywhere but C++ [18:48] because this has to be fast but now this [18:49] is fast enough I can run it in common [18:51] list this function here will take that [18:54] entire box of waters and test every [18:56] water to see if it's in the box and [18:57] throw out the ones that are not in [18:59] box so um compile [19:04] that uh build my two water [19:07] boxes and [19:09] now what I've done [19:12] is I've I've sort of cut a water box on [19:15] the top and the bottom so that now I can [19:17] insert the membrane into [19:21] it [19:26] um and show you the little thing [19:33] okay okay so now this is ready for [19:35] simulation so I've I've built a molecule [19:37] inside a canand do set up a whole [19:39] simulation put water boxes around it [19:42] it's all ready now to put into like one [19:44] of these molecular mechan molecular [19:46] Dynamics engines to simulate this thing [19:48] when you do that this is what you [19:50] see so you're some of the first people [19:52] to see this so this is a simulation that [19:55] took several days of computer time to [19:57] simulate a few NCS of time the the water [20:00] here and above and below is hidden it's [20:03] those Waters up there and all we're [20:04] seeing here is these water molecules [20:06] that filter that sort of flush into the [20:08] voids in the membrane um and uh since [20:11] they flow in this way and they flow in [20:13] that way it's pretty clear that they [20:14] would flow up they would flow down if we [20:16] applied any kind of pressure when we [20:18] calculate how effective this thing could [20:20] be as a water filtration membrane five [20:22] grams of it you hold in your palm with [20:24] your hand could create a membrane the [20:26] size of a football field soccer pitch [20:29] uh and but and and uh about a third of [20:32] that would be space that's available for [20:33] water to pass through it would be a pipe [20:36] size of a third of a football field [20:38] provide enough water for the city and it [20:41] would not require the kind of pressures [20:42] that we need right now basically a [20:44] column of 27 feet of water would fall [20:46] through this membrane right this there [20:48] there is no theoretically there's no way [20:51] in this universe to make a better [20:52] membrane than this and this could be [20:54] used to purify anything water all sorts [20:57] of [20:59] [Applause] [21:02] all right so right now this is a clear [21:03] retical material uh but it I hope I I we [21:06] my lab can make this and we can test it [21:09] so I'm just trying to get money right [21:10] now to to build this this stuff and but [21:13] this simulation is only about four weeks [21:15] old I've only just gotten to this point [21:17] where it can do is fast enough to do [21:19] what I just showed you here where I've [21:20] been able to build molecules again after [21:22] a couple of years of of just working on [21:25] the common list stuff okay I have um I'd [21:29] love to talk to you about all sorts of [21:30] other stuff implementation details I've [21:31] got whole I can mention is one other [21:34] thing [21:35] so class is a common list it's based on [21:39] C++ it's got llvm what I figured out in [21:42] the last couple of weeks is that I can [21:45] take the C++ code and compile it to llvm [21:49] I can take the common list code and [21:50] compile it to [21:52] llvm I can link those together and then [21:55] run llvm passes in lining on everything [21:58] will get inlined into everything [22:01] everything that makes sense and anything [22:02] that doesn't make sense because it's too [22:04] big will get promoted to What's called [22:06] the fast call fast CC calling convention [22:08] where there register matching and stuff [22:10] basically I [22:12] can hook into C++ code with no overhead [22:17] compared to C++ talking to C++ Comm talk [22:20] to C++ with no overhead it's very easy [22:23] to expose C++ libraries inside of class [22:26] list ask me and I'll show you what I'm [22:27] talking about here but basically if you [22:29] want to expose a C++ function you just [22:32] write the C++ you have it in your code [22:34] you put C defon in front of it my [22:37] scraper will find it build an interface [22:40] and make it available to the common Lis [22:42] environment all of clasp is exposed that [22:44] way there's thousands of functions that [22:46] are exposed that way okay thank you very [22:50] [Applause] [22:57] much yeah [23:27] yes uh [23:28] uh so what you would do is you would [23:31] build you would throw some ions into [23:33] this these water areas here and you [23:36] would do what what you see here this is [23:38] this is a molecular Dynamic simulation [23:41] this is simulating the motion of [23:43] molecules by by calculating the forces [23:46] moving the atoms a little bit [23:47] calculating the forces again it's [23:48] hideously slow it takes days to simulate [23:51] nanc of time but that's what dd and [23:54] that's what all these molecular Dynamics [23:55] engines do very well what I'm doing [23:58] doing here is I'm I've got all the code [24:01] to set up the calculations very quickly [24:03] and efficiently but set them up in a way [24:05] where I can [24:06] make millions of different variants of [24:09] them and run these simulations on [24:13] hundreds of thousands of CPUs in [24:15] parallel and then [24:18] automatically uh evaluate them and [24:20] figure out which channels are working [24:21] better than [24:27] other [24:44] this is this is periodic boundary [24:45] conditions yeah yeah [24:53] youim you you track the waters that's [24:56] what we do here we track back how the [24:58] waters move and from that we can [25:00] calculate the Flux Of The Membrane it's [25:04] approximation but we can calculate a [25:05] flux of the membrane and the flux that [25:08] we get is 10 times higher than our [25:10] Aqua this thing is basically acting like [25:13] a c and but yes what you're what you're [25:15] wondering about is exactly what we we do [25:18] we have a way of of of you know we have [25:22] code that will track individual water [25:24] molecules and we're watching which [25:26] molecule water molecules move up and [25:28] sometimes you know if it's if it's [25:29] packed too tight they they won't get in [25:31] there what you'll see is um the waters [25:34] will come in and then bounce right back [25:36] out again if it's too tightly packed and [25:40] um I mean but I don't actually run those [25:43] calculations my collaborators do uh [25:46] they're at the University of Illinois [25:48] and I managed to not the names up oh [25:51] god um they um they've been simulating [25:55] aquaporin for years and they know how to [25:58] sort of [26:01] evaluate no no there's a lot of people [26:03] who do this but it's I can't pronounce [26:05] his last name but it's student Carl I [26:07] work with all the [26:09] time [26:13] car any other [26:21] question filtering anything bigger than [26:25] water uh so ions like sodium Chlor you [26:28] want to fil you want to purify you want [26:30] to turn sea water into drinkable water [26:33] sea water is sodium chloride in water [26:35] and the sodium and the chloride ions [26:37] have Waters wrapped around them and if a [26:39] sodium chlorine ion is going to fit [26:41] through there you have to strip those [26:42] Waters off so if you make the [26:44] constriction tight enough then the [26:47] penalty to strip those Waters off is too [26:49] high for it to get through so what [26:53] happens they accumulate on one end one [26:56] side of the membrane and they have to be [26:57] flush away you would not use this as [26:59] like a dead end pushing stuff through [27:02] you have to use it in a sort of a [27:03] countercurrent flow Arrangement the way [27:05] we do reverse osmosis now you you flow [27:10] sea water over and what you come out [27:12] with on the other side is brine and on [27:14] the other side of the membrane is pure [27:21] water these are very robust I think they [27:24] could be a very very long time our [27:27] aquaporn have like times in in the order [27:29] of hours to days because they are made [27:33] out of [27:34] scrambled um but we constantly recycle [27:37] them but these things are are much more [27:39] robust and they could last a lot longer [27:42] um there's all sorts of issues with [27:44] fouling and uh yeah fouling basically um [27:48] and you'd have to back flush them [27:49] periodically to clear them out um but we [27:52] we do all that stuff with reverse [27:54] osmosis membranes now there's nothing [27:56] these are better than reverse Osmos [27:59] I [27:59] mean membres are just terrible [28:03] technology they just the [28:05] best in my function as eke keeper maybe [28:09] you can