Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
198 views
ubuntu2404
# Computational Chemistry LaTeX Template Makefile
# Optimized for CoCalc with PythonTeX integration
# Keywords: computational chemistry makefile, pythontex latex, molecular dynamics compilation

# Main document name (without .tex extension)
MAIN = main

# LaTeX compiler
LATEX = pdflatex

# PythonTeX executable
PYTHONTEX = pythontex

# Additional flags for LaTeX compilation
LATEX_FLAGS = -shell-escape -interaction=nonstopmode -halt-on-error

# Build directory
BUILD_DIR = build

# Assets directory
ASSETS_DIR = assets

# Default target
.PHONY: all
all: $(MAIN).pdf

# Main compilation target with PythonTeX support
$(MAIN).pdf: $(MAIN).tex
	@echo "Building computational chemistry template with PythonTeX..."
	@mkdir -p $(BUILD_DIR)
	@mkdir -p $(ASSETS_DIR)

	# First LaTeX run to generate .pytxcode file
	$(LATEX) $(LATEX_FLAGS) $(MAIN).tex

	# Run PythonTeX to execute embedded Python code
	@if [ -f $(MAIN).pytxcode ]; then \
		echo "Running PythonTeX for molecular calculations..."; \
		$(PYTHONTEX) $(MAIN).tex; \
	fi

	# Second LaTeX run to incorporate PythonTeX results
	$(LATEX) $(LATEX_FLAGS) $(MAIN).tex

	# Third run for cross-references and citations
	$(LATEX) $(LATEX_FLAGS) $(MAIN).tex

	@echo "Computational chemistry template compiled successfully!"
	@echo "Generated figures saved in: $(ASSETS_DIR)/"
	@echo "PDF output: $(MAIN).pdf"

# Quick build without cleaning
.PHONY: quick
quick:
	$(LATEX) $(LATEX_FLAGS) $(MAIN).tex

# Clean auxiliary files but keep PDF and assets
.PHONY: clean
clean:
	@echo "Cleaning auxiliary files..."
	rm -f $(MAIN).aux $(MAIN).log $(MAIN).out $(MAIN).toc $(MAIN).bbl $(MAIN).blg
	rm -f $(MAIN).fdb_latexmk $(MAIN).fls $(MAIN).synctex.gz
	rm -f $(MAIN).pytxcode $(MAIN).pytxmcr $(MAIN).pytxpyg
	rm -f pythontex-files-$(MAIN)/*
	@echo "Auxiliary files cleaned."

# Deep clean including PDF and generated assets
.PHONY: distclean
distclean: clean
	@echo "Performing deep clean..."
	rm -f $(MAIN).pdf
	rm -rf $(BUILD_DIR)
	rm -f $(ASSETS_DIR)/*.pdf $(ASSETS_DIR)/*.png $(ASSETS_DIR)/*.jpg
	rm -rf pythontex-files-$(MAIN)
	@echo "All generated files removed."

# Force rebuild
.PHONY: rebuild
rebuild: distclean all

# Install required Python packages for computational chemistry
.PHONY: install-deps
install-deps:
	@echo "Installing Python dependencies for computational chemistry..."
	pip install --user numpy matplotlib scipy seaborn pandas
	pip install --user rdkit-pypi  # For cheminformatics (if available)
	@echo "Dependencies installed. Note: Some packages may require system installation."

# Validate template compilation
.PHONY: test
test:
	@echo "Testing computational chemistry template compilation..."
	@make clean
	@make all
	@if [ -f $(MAIN).pdf ]; then \
		echo "✓ Template compilation successful"; \
		echo "✓ PDF generated: $(MAIN).pdf"; \
		ls -la $(ASSETS_DIR)/*.pdf 2>/dev/null && echo "✓ Figures generated in assets/" || echo "! No figures found"; \
	else \
		echo "✗ Template compilation failed"; \
		exit 1; \
	fi

# Show template information
.PHONY: info
info:
	@echo "=== Computational Chemistry LaTeX Template ==="
	@echo "Main file: $(MAIN).tex"
	@echo "Compiler: $(LATEX) with flags: $(LATEX_FLAGS)"
	@echo "PythonTeX: $(PYTHONTEX)"
	@echo "Assets directory: $(ASSETS_DIR)/"
	@echo "Build directory: $(BUILD_DIR)/"
	@echo ""
	@echo "Available targets:"
	@echo "  all         - Build complete template with PythonTeX"
	@echo "  quick       - Quick compilation without PythonTeX"
	@echo "  clean       - Remove auxiliary files"
	@echo "  distclean   - Remove all generated files"
	@echo "  rebuild     - Clean and rebuild everything"
	@echo "  install-deps - Install required Python packages"
	@echo "  test        - Validate template compilation"
	@echo "  info        - Show this information"
	@echo ""
	@echo "Keywords: computational chemistry, molecular dynamics, quantum chemistry"
	@echo "Features: DFT calculations, MD analysis, drug discovery, protein-ligand"

# Help target
.PHONY: help
help: info