An infrastructure Python package of the AlphaX ecosystem for MS proteomics
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive cheminformatics capabilities for peptide and amino acid SMILES (Simplified Molecular-Input Line-Entry System) representations. Provides tools for chemical structure encoding, modification representation, and integration with computational chemistry workflows in proteomics.
Advanced system for modifying amino acid chemical structures using SMILES notation and applying chemical transformations.
class AminoAcidModifier:
"""Chemical modification system for amino acids using SMILES representations."""
def __init__(self):
"""Initialize amino acid modifier with default chemical data."""
def get_amino_acid_smiles(self, aa_code: str) -> str:
"""
Get SMILES representation for amino acid.
Parameters:
- aa_code: Single letter amino acid code
Returns:
SMILES string representing the amino acid structure
"""
def apply_modification(self, aa_smiles: str,
modification_smiles: str,
reaction_site: str = 'auto') -> str:
"""
Apply chemical modification to amino acid SMILES.
Parameters:
- aa_smiles: Original amino acid SMILES
- modification_smiles: SMILES of modification to apply
- reaction_site: Specific reaction site or 'auto' for automatic detection
Returns:
Modified amino acid SMILES string
"""
def create_modified_aa_library(self, modifications: List[dict]) -> dict:
"""
Create library of modified amino acids.
Parameters:
- modifications: List of modification definitions with SMILES
Returns:
Dictionary mapping modified AA codes to SMILES representations
"""
def validate_modification_chemistry(self, aa_code: str,
modification: str) -> dict:
"""
Validate chemical feasibility of amino acid modification.
Parameters:
- aa_code: Amino acid code
- modification: Modification name or SMILES
Returns:
Dictionary with validation results and chemical properties
"""
def calculate_modification_properties(self, modified_smiles: str) -> dict:
"""
Calculate chemical properties of modified amino acid.
Parameters:
- modified_smiles: SMILES of modified amino acid
Returns:
Dictionary with molecular weight, formula, logP, etc.
"""
def get_modification_reaction_mechanism(self, modification: str) -> dict:
"""
Get reaction mechanism for modification.
Parameters:
- modification: Modification name
Returns:
Dictionary with reaction details and mechanism
"""
def load_amino_acid_smiles_database() -> dict:
"""
Load comprehensive database of amino acid SMILES representations.
Returns:
Dictionary mapping amino acid codes to SMILES strings
"""
def create_custom_amino_acid(smiles: str,
aa_code: str,
name: str = None) -> dict:
"""
Create custom amino acid definition from SMILES.
Parameters:
- smiles: SMILES representation of the amino acid
- aa_code: Single letter code for the amino acid
- name: Optional full name for the amino acid
Returns:
Dictionary with amino acid definition
"""
def validate_amino_acid_smiles(smiles: str) -> dict:
"""
Validate SMILES string for amino acid structure.
Parameters:
- smiles: SMILES string to validate
Returns:
Dictionary with validation results and structural analysis
"""System for converting peptide sequences to complete chemical structure representations using SMILES notation.
class PeptideSmilesEncoder:
"""Encoder for converting peptide sequences to SMILES representations."""
def __init__(self, amino_acid_library: dict = None):
"""
Initialize peptide SMILES encoder.
Parameters:
- amino_acid_library: Custom amino acid SMILES library
"""
def encode_peptide_sequence(self, sequence: str,
modifications: List[dict] = None) -> str:
"""
Convert peptide sequence to SMILES representation.
Parameters:
- sequence: Peptide sequence string
- modifications: List of modifications with positions and SMILES
Returns:
Complete SMILES string representing the peptide structure
"""
def encode_modified_peptide(self, sequence: str,
mod_names: List[str],
mod_sites: List[int]) -> str:
"""
Encode peptide with standard modifications to SMILES.
Parameters:
- sequence: Peptide sequence
- mod_names: List of modification names
- mod_sites: List of modification sites (1-indexed)
Returns:
SMILES string with modifications incorporated
"""
def create_peptide_graph(self, sequence: str,
modifications: List[dict] = None) -> object:
"""
Create molecular graph representation of peptide.
Parameters:
- sequence: Peptide sequence
- modifications: Optional modifications
Returns:
Molecular graph object (NetworkX or RDKit Mol)
"""
def calculate_peptide_properties(self, peptide_smiles: str) -> dict:
"""
Calculate chemical properties from peptide SMILES.
Parameters:
- peptide_smiles: SMILES representation of peptide
Returns:
Dictionary with molecular properties (MW, logP, PSA, etc.)
"""
def generate_conformers(self, peptide_smiles: str,
num_conformers: int = 10) -> List[object]:
"""
Generate 3D conformers from peptide SMILES.
Parameters:
- peptide_smiles: SMILES string of peptide
- num_conformers: Number of conformers to generate
Returns:
List of 3D molecular conformer objects
"""
def validate_peptide_structure(self, peptide_smiles: str) -> dict:
"""
Validate peptide SMILES for structural correctness.
Parameters:
- peptide_smiles: Peptide SMILES to validate
Returns:
Dictionary with validation results and structural issues
"""
def fragment_peptide_smiles(self, peptide_smiles: str,
fragmentation_type: str = 'b_y') -> dict:
"""
Generate fragment ion SMILES from peptide SMILES.
Parameters:
- peptide_smiles: Parent peptide SMILES
- fragmentation_type: Type of fragmentation ('b_y', 'cid', 'etd')
Returns:
Dictionary with fragment SMILES and masses
"""
def convert_sequence_to_smiles(sequence: str,
modification_map: dict = None) -> str:
"""
Convert peptide sequence to SMILES using default encoder.
Parameters:
- sequence: Peptide sequence string
- modification_map: Optional modification mappings
Returns:
SMILES representation of the peptide
"""
def batch_encode_peptides(sequences: List[str],
modifications: List[List[dict]] = None,
n_jobs: int = 1) -> List[str]:
"""
Batch encode multiple peptides to SMILES.
Parameters:
- sequences: List of peptide sequences
- modifications: List of modification lists for each peptide
- n_jobs: Number of parallel jobs
Returns:
List of SMILES strings for each peptide
"""Functions for calculating molecular properties and descriptors from SMILES representations.
def calculate_molecular_descriptors(smiles: str) -> dict:
"""
Calculate comprehensive molecular descriptors from SMILES.
Parameters:
- smiles: SMILES string
Returns:
Dictionary with molecular descriptors (MW, logP, TPSA, etc.)
"""
def calculate_lipinski_properties(smiles: str) -> dict:
"""
Calculate Lipinski Rule of Five properties.
Parameters:
- smiles: SMILES string
Returns:
Dictionary with Lipinski properties and compliance
"""
def calculate_peptide_hydrophobicity(smiles: str) -> float:
"""
Calculate peptide hydrophobicity from SMILES.
Parameters:
- smiles: Peptide SMILES string
Returns:
Hydrophobicity score
"""
def predict_retention_time_from_smiles(smiles: str,
model_type: str = 'krokhin') -> float:
"""
Predict chromatographic retention time from SMILES.
Parameters:
- smiles: Peptide SMILES string
- model_type: Prediction model ('krokhin', 'ssp', 'ml')
Returns:
Predicted retention time in minutes
"""
def calculate_collision_cross_section_smiles(smiles: str,
charge: int = 1) -> float:
"""
Predict collision cross section from SMILES structure.
Parameters:
- smiles: Peptide SMILES string
- charge: Ion charge state
Returns:
Predicted CCS value in Ųa
"""
def assess_fragmentation_propensity(smiles: str) -> dict:
"""
Assess peptide fragmentation propensity from structure.
Parameters:
- smiles: Peptide SMILES string
Returns:
Dictionary with fragmentation predictions
"""Tools for analyzing and comparing chemical structures using SMILES representations.
def calculate_tanimoto_similarity(smiles1: str, smiles2: str) -> float:
"""
Calculate Tanimoto similarity between two SMILES structures.
Parameters:
- smiles1: First SMILES string
- smiles2: Second SMILES string
Returns:
Tanimoto similarity coefficient (0-1)
"""
def find_structural_motifs(smiles: str, motif_patterns: List[str]) -> dict:
"""
Find structural motifs in SMILES representation.
Parameters:
- smiles: SMILES string to analyze
- motif_patterns: List of SMARTS patterns to search for
Returns:
Dictionary with motif matches and positions
"""
def cluster_peptides_by_structure(smiles_list: List[str],
similarity_threshold: float = 0.7) -> List[List[int]]:
"""
Cluster peptides based on structural similarity.
Parameters:
- smiles_list: List of SMILES strings
- similarity_threshold: Minimum similarity for clustering
Returns:
List of clusters (lists of indices)
"""
def generate_structural_fingerprints(smiles: str,
fingerprint_type: str = 'morgan') -> object:
"""
Generate molecular fingerprints from SMILES.
Parameters:
- smiles: SMILES string
- fingerprint_type: Type of fingerprint ('morgan', 'maccs', 'topological')
Returns:
Molecular fingerprint object
"""
def identify_functional_groups(smiles: str) -> List[dict]:
"""
Identify functional groups in SMILES structure.
Parameters:
- smiles: SMILES string to analyze
Returns:
List of functional group identifications
"""Integration with modification databases and chemical reaction systems.
class ModificationSmilesDatabase:
"""Database for modification SMILES and reaction patterns."""
def __init__(self, database_path: str = None):
"""
Initialize modification database.
Parameters:
- database_path: Path to custom modification database
"""
def get_modification_smiles(self, modification_name: str) -> str:
"""
Get SMILES representation for named modification.
Parameters:
- modification_name: Standard modification name
Returns:
SMILES string representing the modification
"""
def add_custom_modification(self, name: str,
smiles: str,
reaction_pattern: str = None) -> None:
"""
Add custom modification to database.
Parameters:
- name: Modification name
- smiles: SMILES representation
- reaction_pattern: SMARTS reaction pattern
"""
def search_modifications_by_structure(self, query_smiles: str,
similarity_threshold: float = 0.8) -> List[dict]:
"""
Search modifications by structural similarity.
Parameters:
- query_smiles: Query SMILES structure
- similarity_threshold: Minimum similarity threshold
Returns:
List of matching modifications with similarity scores
"""
def get_reaction_products(self, reactant_smiles: str,
modification_name: str) -> List[str]:
"""
Get reaction products for modification.
Parameters:
- reactant_smiles: Starting amino acid SMILES
- modification_name: Modification to apply
Returns:
List of possible product SMILES
"""
def load_unimod_smiles_mappings() -> dict:
"""
Load SMILES mappings for UniMod modifications.
Returns:
Dictionary mapping UniMod IDs to SMILES representations
"""
def create_reaction_template(reactant_pattern: str,
product_pattern: str) -> object:
"""
Create reaction template from SMARTS patterns.
Parameters:
- reactant_pattern: SMARTS pattern for reactants
- product_pattern: SMARTS pattern for products
Returns:
Reaction template object
"""Tools for visualizing chemical structures and exporting to various formats.
def visualize_peptide_structure(smiles: str,
output_path: str = None,
format: str = 'png') -> object:
"""
Visualize peptide structure from SMILES.
Parameters:
- smiles: SMILES string to visualize
- output_path: Optional path to save image
- format: Output format ('png', 'svg', 'pdf')
Returns:
Image object or None if saved to file
"""
def export_to_sdf(smiles_list: List[str],
output_path: str,
include_properties: bool = True) -> None:
"""
Export SMILES list to SDF format.
Parameters:
- smiles_list: List of SMILES strings
- output_path: Output SDF file path
- include_properties: Include calculated properties
"""
def export_to_mol2(smiles: str, output_path: str) -> None:
"""
Export SMILES to MOL2 format with 3D coordinates.
Parameters:
- smiles: SMILES string
- output_path: Output MOL2 file path
"""
def create_structure_grid(smiles_list: List[str],
labels: List[str] = None,
grid_size: tuple = (4, 4)) -> object:
"""
Create grid visualization of multiple structures.
Parameters:
- smiles_list: List of SMILES to visualize
- labels: Optional labels for each structure
- grid_size: Grid dimensions (rows, columns)
Returns:
Grid image object
"""from alphabase.smiles.smiles import AminoAcidModifier
from alphabase.smiles.peptide import PeptideSmilesEncoder
# Initialize amino acid modifier
modifier = AminoAcidModifier()
# Get SMILES for standard amino acid
cys_smiles = modifier.get_amino_acid_smiles('C')
print(f"Cysteine SMILES: {cys_smiles}")
# Apply carbamidomethyl modification
carbamidomethyl_smiles = "CC(=O)N" # Simplified modification SMILES
modified_cys = modifier.apply_modification(
aa_smiles=cys_smiles,
modification_smiles=carbamidomethyl_smiles,
reaction_site='thiol'
)
print(f"Carbamidomethyl cysteine SMILES: {modified_cys}")
# Calculate properties of modified amino acid
properties = modifier.calculate_modification_properties(modified_cys)
print(f"Modified cysteine properties: {properties}")from alphabase.smiles.peptide import PeptideSmilesEncoder, convert_sequence_to_smiles
# Initialize peptide encoder
encoder = PeptideSmilesEncoder()
# Simple peptide encoding
peptide_seq = "PEPTIDE"
peptide_smiles = encoder.encode_peptide_sequence(peptide_seq)
print(f"Peptide SMILES: {peptide_smiles}")
# Encode peptide with modifications
modified_seq = "PEPTIDE"
mod_names = ["Oxidation (M)"]
mod_sites = [1] # First position (1-indexed)
modified_smiles = encoder.encode_modified_peptide(
sequence=modified_seq,
mod_names=mod_names,
mod_sites=mod_sites
)
print(f"Modified peptide SMILES: {modified_smiles}")
# Calculate peptide properties
properties = encoder.calculate_peptide_properties(peptide_smiles)
print(f"Peptide properties:")
print(f" Molecular weight: {properties['molecular_weight']:.2f}")
print(f" LogP: {properties['logp']:.2f}")
print(f" Polar surface area: {properties['tpsa']:.2f}")from alphabase.smiles.peptide import batch_encode_peptides
from alphabase.smiles.smiles import calculate_molecular_descriptors
# Batch encode multiple peptides
sequences = ["PEPTIDE", "SEQUENCE", "EXAMPLE", "TESTING"]
batch_smiles = batch_encode_peptides(sequences, n_jobs=2)
print(f"Encoded {len(batch_smiles)} peptides to SMILES")
# Calculate descriptors for all peptides
descriptors_list = []
for i, smiles in enumerate(batch_smiles):
descriptors = calculate_molecular_descriptors(smiles)
descriptors['sequence'] = sequences[i]
descriptors_list.append(descriptors)
# Analyze molecular properties
import pandas as pd
descriptors_df = pd.DataFrame(descriptors_list)
print(f"Molecular descriptor statistics:")
print(descriptors_df[['molecular_weight', 'logp', 'tpsa']].describe())from alphabase.smiles.smiles import (
calculate_lipinski_properties, predict_retention_time_from_smiles,
calculate_collision_cross_section_smiles
)
# Example peptide SMILES
peptide_smiles = batch_smiles[0] # From previous example
# Lipinski properties
lipinski = calculate_lipinski_properties(peptide_smiles)
print(f"Lipinski properties: {lipinski}")
print(f"Rule of 5 compliant: {lipinski['compliant']}")
# Predict retention time
predicted_rt = predict_retention_time_from_smiles(peptide_smiles, model_type='krokhin')
print(f"Predicted retention time: {predicted_rt:.2f} minutes")
# Predict collision cross section
predicted_ccs = calculate_collision_cross_section_smiles(peptide_smiles, charge=2)
print(f"Predicted CCS: {predicted_ccs:.1f} Ų")from alphabase.smiles.smiles import (
calculate_tanimoto_similarity, cluster_peptides_by_structure,
find_structural_motifs
)
# Calculate similarity between peptides
smiles1 = batch_smiles[0]
smiles2 = batch_smiles[1]
similarity = calculate_tanimoto_similarity(smiles1, smiles2)
print(f"Tanimoto similarity: {similarity:.3f}")
# Cluster peptides by structural similarity
clusters = cluster_peptides_by_structure(batch_smiles, similarity_threshold=0.6)
print(f"Found {len(clusters)} structural clusters")
for i, cluster in enumerate(clusters):
cluster_sequences = [sequences[idx] for idx in cluster]
print(f" Cluster {i+1}: {cluster_sequences}")
# Find structural motifs
motif_patterns = [
"CC(C)C", # Leucine/Isoleucine side chain
"c1ccccc1", # Benzene ring (Phe, Tyr, Trp)
"CCC(=O)O" # Carboxylic acid
]
for smiles in batch_smiles[:2]:
motifs = find_structural_motifs(smiles, motif_patterns)
print(f"Motifs in {smiles[:20]}...")
for pattern, matches in motifs.items():
if matches:
print(f" Found pattern {pattern}: {len(matches)} matches")from alphabase.smiles.smiles import ModificationSmilesDatabase, load_unimod_smiles_mappings
# Load modification database
mod_db = ModificationSmilesDatabase()
# Get SMILES for common modifications
oxidation_smiles = mod_db.get_modification_smiles("Oxidation (M)")
phospho_smiles = mod_db.get_modification_smiles("Phospho (STY)")
print(f"Oxidation SMILES: {oxidation_smiles}")
print(f"Phosphorylation SMILES: {phospho_smiles}")
# Add custom modification
mod_db.add_custom_modification(
name="Custom_Alkylation",
smiles="CCCC",
reaction_pattern="[#6:1]>>[#6:1]CCCC"
)
# Search for structurally similar modifications
query_smiles = "CC(=O)N"
similar_mods = mod_db.search_modifications_by_structure(
query_smiles,
similarity_threshold=0.7
)
print(f"Similar modifications: {[mod['name'] for mod in similar_mods]}")
# Load UniMod mappings
unimod_smiles = load_unimod_smiles_mappings()
print(f"Loaded {len(unimod_smiles)} UniMod SMILES mappings")# Generate fragment ion SMILES
fragment_smiles = encoder.fragment_peptide_smiles(
peptide_smiles=batch_smiles[0],
fragmentation_type='b_y'
)
print(f"Generated fragments:")
for frag_type, frag_list in fragment_smiles.items():
print(f" {frag_type} ions: {len(frag_list)}")
for frag in frag_list[:3]: # Show first 3
print(f" SMILES: {frag['smiles'][:30]}...")
print(f" Mass: {frag['mass']:.4f}")from alphabase.smiles.smiles import (
visualize_peptide_structure, export_to_sdf, create_structure_grid
)
# Visualize single peptide structure
structure_img = visualize_peptide_structure(
smiles=batch_smiles[0],
output_path='peptide_structure.png',
format='png'
)
# Create grid visualization of multiple structures
grid_img = create_structure_grid(
smiles_list=batch_smiles,
labels=sequences,
grid_size=(2, 2)
)
# Export to SDF format for external analysis
export_to_sdf(
smiles_list=batch_smiles,
output_path='peptides.sdf',
include_properties=True
)
print("Visualization and export completed")from alphabase.smiles.smiles import (
generate_structural_fingerprints, identify_functional_groups,
assess_fragmentation_propensity
)
# Generate molecular fingerprints
fingerprint = generate_structural_fingerprints(
smiles=batch_smiles[0],
fingerprint_type='morgan'
)
print(f"Generated molecular fingerprint with {len(fingerprint)} bits")
# Identify functional groups
functional_groups = identify_functional_groups(batch_smiles[0])
print(f"Functional groups identified:")
for group in functional_groups:
print(f" {group['name']}: {group['count']} occurrences")
# Assess fragmentation propensity
fragmentation = assess_fragmentation_propensity(batch_smiles[0])
print(f"Fragmentation analysis:")
print(f" Predicted dominant fragments: {fragmentation['dominant_fragments']}")
print(f" Fragmentation score: {fragmentation['fragmentation_score']:.2f}")# Example: Integrate SMILES with spectral library
from alphabase.spectral_library.base import SpecLibBase
import pandas as pd
# Create spectral library with SMILES information
spec_lib = SpecLibBase()
spec_lib.precursor_df = pd.DataFrame({
'sequence': sequences,
'mods': ['', '', '', ''],
'charge': [2, 2, 2, 2],
'proteins': ['P1', 'P2', 'P3', 'P4'],
'smiles': batch_smiles
})
# Add chemical properties to spectral library
for idx, row in spec_lib.precursor_df.iterrows():
props = calculate_molecular_descriptors(row['smiles'])
spec_lib.precursor_df.loc[idx, 'molecular_weight'] = props['molecular_weight']
spec_lib.precursor_df.loc[idx, 'logp'] = props['logp']
spec_lib.precursor_df.loc[idx, 'predicted_rt'] = predict_retention_time_from_smiles(row['smiles'])
print(f"Enhanced spectral library with chemical properties:")
print(spec_lib.precursor_df[['sequence', 'molecular_weight', 'logp', 'predicted_rt']].head())Install with Tessl CLI
npx tessl i tessl/pypi-alphabase