Bead-Spring¶
AutoPoly.models.bead_spring
¶
Bead-Spring Polymer Model Module
This module provides the BeadSpringPolymer class for generating coarse-grained bead-spring polymer models for molecular dynamics simulations in LAMMPS.
Features: - Multiple bead types (block copolymers) - Per-triplet angle stiffness - FENE bond support - Linear and ring topologies - Monte Carlo pre-equilibration for initial configurations
Classes:
| Name | Description |
|---|---|
BeadType |
LJ parameters for a bead type. |
AngleType |
Angle parameters for a bead triplet. |
SAWConfig |
Configuration for Self-Avoiding Random Walk generation. |
MCConfig |
Monte Carlo equilibration configuration. |
BeadSpringPolymer |
Bead-spring polymer model generator for LAMMPS simulations. |
Functions:
| Name | Description |
|---|---|
calculate_box_size |
Calculate cubic box size from number of beads and target density. |
compute_lj_energy |
Compute total LJ energy for non-bonded pairs. |
compute_lj_energy_vectorized |
Vectorized LJ energy using numpy broadcasting. |
compute_local_lj_energy |
Compute LJ energy contribution from one bead to all others - O(N). |
compute_local_bond_energy |
Compute bond energy for bonds involving a specific bead - O(degree). |
compute_bond_energy |
Compute harmonic bond energy. |
compute_bond_energy_vectorized |
Vectorized bond energy calculation. |
compute_total_energy |
Compute total system energy for Metropolis criterion. |
build_exclusion_structures |
Build exclusion data structures for efficient energy calculations. |
metropolis_accept |
Metropolis acceptance criterion. |
mc_single_bead_displacement |
Displace a single bead by random vector. |
mc_crankshaft_move |
Rotate beads between i and j around the i-j axis. |
mc_pivot_move |
Rotate arm (pivot_idx+1 to chain_end) around pivot bead. |
mc_reptation_move |
Remove bead from one end (tail) and attach at other end (head). |
mc_tree_pivot_move |
Rotate a subtree of beads around a random axis through the pivot bead. |
mc_segment_crankshaft_move |
Crankshaft move along an explicit bead path (segment). |
build_chain_graph |
Build per-chain graph metadata for branched MC moves. |
place_chains_in_box |
Place multiple chains randomly in periodic box. |
mc_chain_translation |
Translate entire chain by random displacement with PBC. |
mc_chain_rotation |
Rotate entire chain around its center of mass. |
saw_grow_chain |
Grow a single polymer chain using Self-Avoiding Random Walk with backtracking. |
saw_generate_multi_chain |
Generate multiple polymer chains using SAW. |
saw_grow_graph |
Grow a single chain of arbitrary architecture using SAW with backtracking. |
saw_generate_graphs |
Generate multiple chains of (possibly different) architectures using SAW. |
mc_equilibrate |
Pre-equilibrate polymer configuration using MC moves. |
canonical_bead_triplet |
Return canonical triplet (smaller endpoint first alphabetically). |
lb_pair_coeffs |
Lorentz-Berthelot mixing for all bead type pairs. |
resolve_angle_params |
Return (k, theta0) for a canonical triplet, using defaults if unset. |
build_angle_type_map |
Map canonical triplets to LAMMPS angle type IDs across all chains. |
write_lammps_input_script |
Write the LAMMPS input script (in.polymer) for a bead-spring system. |
BeadType
dataclass
¶
AngleType
dataclass
¶
SAWConfig
dataclass
¶
Configuration for Self-Avoiding Random Walk generation.
Source code in AutoPoly/models/bead_spring.py
MCConfig
dataclass
¶
Monte Carlo equilibration configuration.
Source code in AutoPoly/models/bead_spring.py
BeadSpringPolymer
¶
Bead-spring polymer model generator for LAMMPS simulations.
Supports multiple bead types for block copolymers, per-triplet angle stiffness, and both harmonic and FENE bond styles.
Methods:
| Name | Description |
|---|---|
equilibrate |
Pre-equilibrate the polymer configuration using Monte Carlo moves. |
saw_generate |
Generate configuration using Self-Avoiding Random Walk. |
generate |
Generate LAMMPS input files using the configured output backend. |
generate_data_file |
Generate LAMMPS data file for bead-spring polymer (direct backend). |
generate_moltemplate |
Generate moltemplate .lt files (and optionally run moltemplate) for |
get_system_info |
Get comprehensive information about the bead-spring polymer system. |
kremer_grest |
Create a Kremer-Grest bead-spring polymer with standard parameters. |
Attributes:
| Name | Type | Description |
|---|---|---|
n_beads |
int
|
Number of beads per chain (derived from sequence). |
Source code in AutoPoly/models/bead_spring.py
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 | |
n_beads: int
property
¶
Number of beads per chain (derived from sequence).
equilibrate(mc_config: Optional[MCConfig] = None) -> None
¶
Pre-equilibrate the polymer configuration using Monte Carlo moves.
Updates internal positions in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc_config
|
Optional[MCConfig]
|
Monte Carlo configuration. Uses instance config or defaults. |
None
|
Source code in AutoPoly/models/bead_spring.py
saw_generate(saw_config: Optional[SAWConfig] = None) -> bool
¶
Generate configuration using Self-Avoiding Random Walk.
This is a fast alternative to MC equilibration that generates overlap-free configurations directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saw_config
|
Optional[SAWConfig]
|
SAW configuration. Uses instance config or defaults. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if SAW failed. |
Source code in AutoPoly/models/bead_spring.py
2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 | |
generate(backend: Optional[str] = None, run_moltemplate: bool = True) -> None
¶
Generate LAMMPS input files using the configured output backend.
This is the standard entry point for producing simulation files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Optional[str]
|
"moltemplate" (default; .lt files + moltemplate ->
moltemplate/system.data + system.in.*) or "direct"
(polymer.data + in.polymer written directly). Defaults to
the constructor's |
None
|
run_moltemplate
|
bool
|
Only for the moltemplate backend: run the bundled moltemplate after writing .lt files. |
True
|
Source code in AutoPoly/models/bead_spring.py
generate_data_file() -> None
¶
Generate LAMMPS data file for bead-spring polymer (direct backend).
Source code in AutoPoly/models/bead_spring.py
2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 | |
generate_moltemplate(run_moltemplate: bool = True) -> Path
¶
Generate moltemplate .lt files (and optionally run moltemplate) for this bead-spring polymer.
Mirrors the atomistic pipeline layout under
<path>/moltemplate/: bead_spring.lt (CG force field),
bead_
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_moltemplate
|
bool
|
Run the bundled moltemplate after writing files (produces system.data, system.in.init/settings). |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the moltemplate directory. |
Source code in AutoPoly/models/bead_spring.py
get_system_info() -> dict
¶
Get comprehensive information about the bead-spring polymer system.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing system properties. |
Source code in AutoPoly/models/bead_spring.py
kremer_grest(name: str, system: object, n_chains: int, n_beads: int, topology: str = 'linear', density: float = 0.74, generation_method: str = 'saw') -> BeadSpringPolymer
classmethod
¶
Create a Kremer-Grest bead-spring polymer with standard parameters.
The Kremer-Grest model is a standard coarse-grained polymer model used for universal polymer behavior studies. It uses: - FENE bonds (K=30, R0=1.5) - WCA purely repulsive interactions (cutoff = 2^(1/6)*sigma ≈ 1.12246) - Standard LJ parameters (epsilon=1.0, sigma=1.0, mass=1.0)
The equilibrium bond length of ~0.97 EMERGES from the balance of FENE (attractive) + WCA (repulsive) - there is no explicit r0 parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for output files. |
required |
system
|
object
|
System object containing path information. |
required |
n_chains
|
int
|
Number of polymer chains. |
required |
n_beads
|
int
|
Number of beads per chain. |
required |
topology
|
str
|
"linear" or "ring" topology. |
'linear'
|
density
|
float
|
Target bead density (beads/sigma^3). Default 0.74 for initial placement (will compress to ~0.85-0.90 during NPT). |
0.74
|
generation_method
|
str
|
Method for generating initial configurations ("geometric", "saw", or "mc"). |
'saw'
|
Returns:
| Type | Description |
|---|---|
BeadSpringPolymer
|
BeadSpringPolymer instance configured for Kremer-Grest model. |
Example
from AutoPoly import System from AutoPoly import BeadSpringPolymer system = System(out="kg_simulation") kg_polymer = BeadSpringPolymer.kremer_grest( ... name="kg_melt", ... system=system, ... n_chains=100, ... n_beads=10, ... topology="linear" ... ) kg_polymer.generate_data_file()
References
Kremer, K., & Grest, G. S. (1990). Dynamics of entangled linear polymer melts: A molecular-dynamics simulation. J. Chem. Phys. 92(8), 5057-5086.
Source code in AutoPoly/models/bead_spring.py
3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 | |
calculate_box_size(n_beads: int, density: float = DEFAULT_BEAD_DENSITY) -> float
¶
Calculate cubic box size from number of beads and target density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_beads
|
int
|
Total number of beads in system. |
required |
density
|
float
|
Target bead density (beads per sigma^3). |
DEFAULT_BEAD_DENSITY
|
Returns:
| Type | Description |
|---|---|
float
|
Side length of cubic box. |
Formula: V = n_beads / density, box_size = V^(1/3)
Source code in AutoPoly/models/bead_spring.py
compute_lj_energy(positions: Union[List[np.ndarray], np.ndarray], sigma: float = 1.0, epsilon: float = 1.0, cutoff: float = 2.5, exclude_bonded: Optional[List[Tuple[int, int]]] = None, box_size: Optional[float] = None) -> float
¶
Compute total LJ energy for non-bonded pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array for each bead. |
required |
sigma
|
float
|
LJ sigma parameter. |
1.0
|
epsilon
|
float
|
LJ epsilon parameter. |
1.0
|
cutoff
|
float
|
Cutoff distance in units of sigma. |
2.5
|
exclude_bonded
|
Optional[List[Tuple[int, int]]]
|
List of bonded pairs (i, j) to exclude from LJ calculation. |
None
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions (None = no PBC). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Total LJ energy. |
Source code in AutoPoly/models/bead_spring.py
compute_lj_energy_vectorized(positions: np.ndarray, excluded_mask: np.ndarray, sigma: float = 1.0, epsilon: float = 1.0, cutoff: float = 2.5, box_size: Optional[float] = None) -> float
¶
Vectorized LJ energy using numpy broadcasting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) array of bead positions. |
required |
excluded_mask
|
ndarray
|
(N, N) boolean array where True means pair is excluded. |
required |
sigma
|
float
|
LJ sigma parameter. |
1.0
|
epsilon
|
float
|
LJ epsilon parameter. |
1.0
|
cutoff
|
float
|
Cutoff distance in units of sigma. |
2.5
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Total LJ energy. |
Source code in AutoPoly/models/bead_spring.py
compute_local_lj_energy(positions: np.ndarray, bead_idx: int, excluded_set: set, sigma: float = 1.0, epsilon: float = 1.0, cutoff: float = 2.5, box_size: Optional[float] = None) -> float
¶
Compute LJ energy contribution from one bead to all others - O(N).
This is the key optimization: instead of recomputing O(N²) energy, we only compute the O(N) interactions involving the moved bead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) array of bead positions. |
required |
bead_idx
|
int
|
Index of the bead to compute interactions for. |
required |
excluded_set
|
set
|
Set of bead indices that are bonded to bead_idx. |
required |
sigma
|
float
|
LJ sigma parameter. |
1.0
|
epsilon
|
float
|
LJ epsilon parameter. |
1.0
|
cutoff
|
float
|
Cutoff distance in units of sigma. |
2.5
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
LJ energy contribution from bead_idx to all other beads. |
Source code in AutoPoly/models/bead_spring.py
compute_local_bond_energy(positions: np.ndarray, bead_idx: int, bead_bonds: List[int], k_bond: float = 100.0, r0: float = 1.0, box_size: Optional[float] = None) -> float
¶
Compute bond energy for bonds involving a specific bead - O(degree).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) array of bead positions. |
required |
bead_idx
|
int
|
Index of the bead. |
required |
bead_bonds
|
List[int]
|
List of bead indices that are bonded to bead_idx. |
required |
k_bond
|
float
|
Bond spring constant. |
100.0
|
r0
|
float
|
Equilibrium bond length. |
1.0
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Bond energy contribution from bead_idx. |
Source code in AutoPoly/models/bead_spring.py
compute_bond_energy(positions: Union[List[np.ndarray], np.ndarray], bonds: List[Tuple[int, int]], k_bond: float = 100.0, r0: float = 1.0, box_size: Optional[float] = None) -> float
¶
Compute harmonic bond energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array for each bead. |
required |
bonds
|
List[Tuple[int, int]]
|
List of (atom1_idx, atom2_idx) tuples (0-indexed). |
required |
k_bond
|
float
|
Bond spring constant. |
100.0
|
r0
|
float
|
Equilibrium bond length. |
1.0
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Total bond energy. |
Source code in AutoPoly/models/bead_spring.py
compute_bond_energy_vectorized(positions: np.ndarray, bonds: np.ndarray, k_bond: float = 100.0, r0: float = 1.0, box_size: Optional[float] = None) -> float
¶
Vectorized bond energy calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) array of bead positions. |
required |
bonds
|
ndarray
|
(M, 2) array of bond pairs. |
required |
k_bond
|
float
|
Bond spring constant. |
100.0
|
r0
|
float
|
Equilibrium bond length. |
1.0
|
box_size
|
Optional[float]
|
Box size for periodic boundary conditions. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Total bond energy. |
Source code in AutoPoly/models/bead_spring.py
compute_total_energy(positions: Union[List[np.ndarray], np.ndarray], bonds: List[Tuple[int, int]], lj_sigma: float = 1.0, lj_epsilon: float = 1.0, lj_cutoff: float = 2.5, bond_k: float = 100.0, bond_r0: float = 1.0, box_size: Optional[float] = None) -> float
¶
Compute total system energy for Metropolis criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array for each bead. |
required |
bonds
|
List[Tuple[int, int]]
|
List of (atom1_idx, atom2_idx) tuples. |
required |
lj_sigma
|
float
|
LJ sigma parameter. |
1.0
|
lj_epsilon
|
float
|
LJ epsilon parameter. |
1.0
|
lj_cutoff
|
float
|
LJ cutoff in sigma units. |
2.5
|
bond_k
|
float
|
Bond spring constant. |
100.0
|
bond_r0
|
float
|
Equilibrium bond length. |
1.0
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Total energy (LJ + bond). |
Source code in AutoPoly/models/bead_spring.py
build_exclusion_structures(n_beads: int, bonds: List[Tuple[int, int]]) -> Tuple[np.ndarray, List[set], List[List[int]]]
¶
Build exclusion data structures for efficient energy calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_beads
|
int
|
Total number of beads. |
required |
bonds
|
List[Tuple[int, int]]
|
List of (atom1_idx, atom2_idx) tuples. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of: |
List[set]
|
|
List[List[int]]
|
|
Tuple[ndarray, List[set], List[List[int]]]
|
|
Source code in AutoPoly/models/bead_spring.py
metropolis_accept(delta_E: float, temperature: float = 1.0) -> bool
¶
Metropolis acceptance criterion.
Accept if delta_E <= 0, else accept with probability exp(-delta_E/T).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_E
|
float
|
Energy change. |
required |
temperature
|
float
|
Reduced temperature. |
1.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if move should be accepted. |
Source code in AutoPoly/models/bead_spring.py
mc_single_bead_displacement(positions: Union[List[np.ndarray], np.ndarray], bead_idx: int, max_disp: float = 0.5, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Displace a single bead by random vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
bead_idx
|
int
|
Index of bead to displace. |
required |
max_disp
|
float
|
Maximum displacement in each direction. |
0.5
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_crankshaft_move(positions: Union[List[np.ndarray], np.ndarray], chain_start: int, chain_end: int, max_angle: float = 0.3, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Rotate beads between i and j around the i-j axis.
Keeps beads i and j fixed; rotates all beads strictly between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
chain_start
|
int
|
Start index of the chain. |
required |
chain_end
|
int
|
End index of the chain (exclusive). |
required |
max_angle
|
float
|
Maximum rotation angle in radians. |
0.3
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_pivot_move(positions: Union[List[np.ndarray], np.ndarray], chain_start: int, chain_end: int, max_angle: float = 0.3, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Rotate arm (pivot_idx+1 to chain_end) around pivot bead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
chain_start
|
int
|
Start index of the chain. |
required |
chain_end
|
int
|
End index of the chain (exclusive). |
required |
max_angle
|
float
|
Maximum rotation angle in radians. |
0.3
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_reptation_move(positions: Union[List[np.ndarray], np.ndarray], chain_start: int, chain_end: int, bond_length: float = 1.0, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Remove bead from one end (tail) and attach at other end (head).
Slithering snake move that maintains chain connectivity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
chain_start
|
int
|
Start index of the chain. |
required |
chain_end
|
int
|
End index of the chain (exclusive). |
required |
bond_length
|
float
|
Bond length for new position. |
1.0
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_tree_pivot_move(positions: Union[List[np.ndarray], np.ndarray], pivot_idx: int, subtree_indices: List[int], max_angle: float = 0.3, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Rotate a subtree of beads around a random axis through the pivot bead.
This is the graph generalization of the pivot move for branched
architectures: cutting edge (pivot, q) splits the molecule; the subtree
on q's side (subtree_indices, must include q) is rotated rigidly.
Because the rotation axis passes through the pivot bead, the (pivot, q)
bond length and all internal subtree bonds are preserved exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
pivot_idx
|
int
|
Index of the pivot bead (rotation axis passes through it). |
required |
subtree_indices
|
List[int]
|
Indices of beads to rotate (the component beyond the cut edge, including q). |
required |
max_angle
|
float
|
Maximum rotation angle (radians). |
0.3
|
box_size
|
Optional[float]
|
Box size for PBC wrapping. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_segment_crankshaft_move(positions: Union[List[np.ndarray], np.ndarray], segment: List[int], max_angle: float = 0.3, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Crankshaft move along an explicit bead path (segment).
Graph generalization of :func:mc_crankshaft_move for branched
architectures: two beads i, j are chosen along the segment path (with at
least two path beads between them) and the path beads strictly between
them are rotated around the i-j axis. The segment must be a genuine bond
path so all rotated bonds are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
segment
|
List[int]
|
Bead indices forming a connected path (length >= 4). |
required |
max_angle
|
float
|
Maximum rotation angle in radians. |
0.3
|
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
build_chain_graph(architecture: BeadArchitecture, start: int) -> Dict[str, any]
¶
Build per-chain graph metadata for branched MC moves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
architecture
|
BeadArchitecture
|
The chain's BeadArchitecture. |
required |
start
|
int
|
Global index of the chain's first bead (bead i of the
architecture maps to global index |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, any]
|
Dict with keys: - "branched": True if any bead has degree > 2 or the graph is not a simple path - "adjacency": global-index adjacency dict - "edges": global-index bond list - "pivot_edges": bridge edges valid for tree-pivot moves - "segments": linear bead paths valid for segment crankshaft |
Source code in AutoPoly/models/bead_spring.py
place_chains_in_box(chain_positions: List[List[np.ndarray]], box_size: float, min_separation: float = 2.0, max_attempts: int = 1000) -> Tuple[List[np.ndarray], List[Tuple[int, int]]]
¶
Place multiple chains randomly in periodic box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_positions
|
List[List[ndarray]]
|
List of chain positions (each chain is list of np.array). |
required |
box_size
|
float
|
Cubic box side length. |
required |
min_separation
|
float
|
Minimum distance between chain COMs. |
2.0
|
max_attempts
|
int
|
Maximum placement attempts per chain. |
1000
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
Tuple of (all_positions, chain_indices) where chain_indices is |
List[Tuple[int, int]]
|
list of (start, end) indices for each chain. |
Source code in AutoPoly/models/bead_spring.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
mc_chain_translation(positions: Union[List[np.ndarray], np.ndarray], chain_indices: List[Tuple[int, int]], chain_idx: int, max_disp: float, box_size: float) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Translate entire chain by random displacement with PBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
chain_indices
|
List[Tuple[int, int]]
|
List of (start, end) indices for each chain. |
required |
chain_idx
|
int
|
Index of chain to translate. |
required |
max_disp
|
float
|
Maximum displacement. |
required |
box_size
|
float
|
Box size for PBC. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
mc_chain_rotation(positions: Union[List[np.ndarray], np.ndarray], chain_indices: List[Tuple[int, int]], chain_idx: int, max_angle: float, box_size: Optional[float] = None) -> Tuple[Union[List[np.ndarray], np.ndarray], bool]
¶
Rotate entire chain around its center of mass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of position arrays or (N, 3) array. |
required |
chain_indices
|
List[Tuple[int, int]]
|
List of (start, end) indices for each chain. |
required |
chain_idx
|
int
|
Index of chain to rotate. |
required |
max_angle
|
float
|
Maximum rotation angle. |
required |
box_size
|
Optional[float]
|
Box size for PBC. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Union[List[ndarray], ndarray], bool]
|
Tuple of (new_positions, is_valid). |
Source code in AutoPoly/models/bead_spring.py
saw_grow_chain(n_beads: int, bond_length: float, start_position: np.ndarray, collision_detector: CollisionDetector, config: SAWConfig, topology: str = 'linear', chain_id_offset: int = 0) -> Tuple[Optional[List[np.ndarray]], int]
¶
Grow a single polymer chain using Self-Avoiding Random Walk with backtracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_beads
|
int
|
Number of beads in the chain. |
required |
bond_length
|
float
|
Distance between consecutive beads. |
required |
start_position
|
ndarray
|
Position of the first bead. |
required |
collision_detector
|
CollisionDetector
|
CollisionDetector for checking overlaps. |
required |
config
|
SAWConfig
|
SAWConfig with algorithm parameters. |
required |
topology
|
str
|
"linear" or "ring". |
'linear'
|
chain_id_offset
|
int
|
Offset for bead IDs in collision detector. |
0
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[List[ndarray]], int]
|
Tuple of (positions, backtracks_used) where positions is None if failed. |
Source code in AutoPoly/models/bead_spring.py
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 | |
saw_generate_multi_chain(n_chains: int, n_beads_per_chain: int, bond_length: float, box_size: float, config: SAWConfig, topology: str = 'linear', max_start_attempts: int = 100) -> Tuple[Optional[List[np.ndarray]], Optional[List[Tuple[int, int]]], Dict[str, any]]
¶
Generate multiple polymer chains using SAW.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_chains
|
int
|
Number of chains to generate. |
required |
n_beads_per_chain
|
int
|
Beads per chain. |
required |
bond_length
|
float
|
Bond length between consecutive beads. |
required |
box_size
|
float
|
Cubic box side length. |
required |
config
|
SAWConfig
|
SAWConfig with algorithm parameters. |
required |
topology
|
str
|
"linear" or "ring". |
'linear'
|
max_start_attempts
|
int
|
Max attempts to find valid starting position per chain. |
100
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[List[ndarray]], Optional[List[Tuple[int, int]]], Dict[str, any]]
|
Tuple of (all_positions, chain_indices, stats) or (None, None, stats) if failed. |
Source code in AutoPoly/models/bead_spring.py
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 | |
saw_grow_graph(architecture: BeadArchitecture, bond_length: float, start_position: np.ndarray, collision_detector: CollisionDetector, config: SAWConfig, chain_id_offset: int = 0) -> Tuple[Optional[List[np.ndarray]], int]
¶
Grow a single chain of arbitrary architecture using SAW with backtracking.
Beads are placed along the spanning-tree growth order of the architecture
(BFS from bead 0): each bead is placed at bond_length from its
already-placed parent. Cycle-closing edges (e.g. the ring closure) are
enforced as distance constraints when the second endpoint is placed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
architecture
|
BeadArchitecture
|
BeadArchitecture defining bead connectivity. |
required |
bond_length
|
float
|
Distance between bonded beads. |
required |
start_position
|
ndarray
|
Position of the root bead (bead 0). |
required |
collision_detector
|
CollisionDetector
|
CollisionDetector for checking overlaps. |
required |
config
|
SAWConfig
|
SAWConfig with algorithm parameters. |
required |
chain_id_offset
|
int
|
Offset for bead IDs in collision detector. |
0
|
Returns:
| Type | Description |
|---|---|
Optional[List[ndarray]]
|
Tuple of (positions, backtracks_used); positions is None if failed. |
int
|
|
Source code in AutoPoly/models/bead_spring.py
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 | |
saw_generate_graphs(architectures: List[BeadArchitecture], bond_length: float, box_size: float, config: SAWConfig, max_start_attempts: int = 100, obstacles: Optional[Tuple[np.ndarray, np.ndarray]] = None) -> Tuple[Optional[List[np.ndarray]], Optional[List[Tuple[int, int]]], Dict[str, any]]
¶
Generate multiple chains of (possibly different) architectures using SAW.
This is the graph-based generalization of :func:saw_generate_multi_chain
and also the driver for mixtures: each chain may have its own
architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
architectures
|
List[BeadArchitecture]
|
One BeadArchitecture per chain to generate. |
required |
bond_length
|
float
|
Bond length between bonded beads. |
required |
box_size
|
float
|
Cubic box side length. |
required |
config
|
SAWConfig
|
SAWConfig with algorithm parameters. |
required |
max_start_attempts
|
int
|
Max attempts to find valid starting position. |
100
|
obstacles
|
Optional[Tuple[ndarray, ndarray]]
|
Optional (centers (k, 3), exclusion radii (k,)) of fixed spheres (coarse-grained fillers) no bead may enter. With obstacles, all overlap checks (obstacles and beads) use the periodic minimum image of the box. None (default) leaves the generator unchanged. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[List[ndarray]]
|
Tuple of (all_positions, chain_indices, stats) or |
Optional[List[Tuple[int, int]]]
|
(None, None, stats) if failed. |
Source code in AutoPoly/models/bead_spring.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 | |
mc_equilibrate(positions: Union[List[np.ndarray], np.ndarray], bonds: List[Tuple[int, int]], chain_indices: Optional[List[Tuple[int, int]]] = None, chain_graphs: Optional[List[Dict[str, any]]] = None, n_steps: int = 10000, temperature: float = 1.0, move_weights: Optional[Dict[str, float]] = None, box_size: Optional[float] = None, lj_sigma: float = 1.0, lj_epsilon: float = 1.0, lj_cutoff: float = 2.5, bond_k: float = 100.0, bond_r0: float = 1.0, max_displacement: float = 0.5, max_angle: float = 0.3, verbose: bool = False) -> Tuple[List[np.ndarray], Dict[str, float]]
¶
Pre-equilibrate polymer configuration using MC moves.
This implementation uses local energy updates for single-bead moves, reducing complexity from O(N²) to O(N) per step for the most common move type. For multi-bead moves, full energy recalculation is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Union[List[ndarray], ndarray]
|
List of np.array or (N, 3) array, atom positions. |
required |
bonds
|
List[Tuple[int, int]]
|
List of (atom1_idx, atom2_idx) tuples (0-indexed). |
required |
chain_indices
|
Optional[List[Tuple[int, int]]]
|
List of (start, end) tuples for each chain. If None, treats entire system as one chain. |
None
|
chain_graphs
|
Optional[List[Dict[str, any]]]
|
Optional per-chain graph metadata for branched
architectures (see :func: |
None
|
n_steps
|
int
|
Number of MC steps. |
10000
|
temperature
|
float
|
Reduced temperature. |
1.0
|
move_weights
|
Optional[Dict[str, float]]
|
Dict of move type probabilities. |
None
|
box_size
|
Optional[float]
|
Apply PBC if specified. |
None
|
lj_sigma
|
float
|
LJ sigma parameter. |
1.0
|
lj_epsilon
|
float
|
LJ epsilon parameter. |
1.0
|
lj_cutoff
|
float
|
LJ cutoff in sigma units. |
2.5
|
bond_k
|
float
|
Bond spring constant. |
100.0
|
bond_r0
|
float
|
Equilibrium bond length. |
1.0
|
max_displacement
|
float
|
Max displacement for single bead moves. |
0.5
|
max_angle
|
float
|
Max rotation angle for pivot/crankshaft. |
0.3
|
verbose
|
bool
|
Print progress. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[List[ndarray], Dict[str, float]]
|
Tuple of (equilibrated_positions, acceptance_stats). |
Source code in AutoPoly/models/bead_spring.py
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 | |
canonical_bead_triplet(t1: str, t2: str, t3: str) -> Tuple[str, str, str]
¶
Return canonical triplet (smaller endpoint first alphabetically).
lb_pair_coeffs(bead_types: List[BeadType]) -> Dict[Tuple[int, int], Tuple[float, float]]
¶
Lorentz-Berthelot mixing for all bead type pairs.
Returns:
| Type | Description |
|---|---|
Dict[Tuple[int, int], Tuple[float, float]]
|
Dict mapping (type_i, type_j) (1-based) to (epsilon_ij, sigma_ij). |
Source code in AutoPoly/models/bead_spring.py
resolve_angle_params(triplet: Tuple[str, str, str], angle_types: List[AngleType], default_k: float, default_theta0: float) -> Tuple[float, float]
¶
Return (k, theta0) for a canonical triplet, using defaults if unset.
Source code in AutoPoly/models/bead_spring.py
build_angle_type_map(chain_bead_types: List[List[str]], chain_triplets: List[List[Tuple[int, int, int]]]) -> Dict[Tuple[str, str, str], int]
¶
Map canonical triplets to LAMMPS angle type IDs across all chains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_bead_types
|
List[List[str]]
|
Bead type names per chain. |
required |
chain_triplets
|
List[List[Tuple[int, int, int]]]
|
Local (i, j, k) triplets per chain. |
required |
Returns:
| Type | Description |
|---|---|
Dict[Tuple[str, str, str], int]
|
Dict mapping canonical triplet to 1-based angle type ID. |
Source code in AutoPoly/models/bead_spring.py
write_lammps_input_script(path: str, bead_types: List[BeadType], pair_coeffs: Dict[Tuple[int, int], Tuple[float, float]], bond_style: str, k_bond: float, bond_length: float, fene_r0: float, pair_style: str, use_angles: bool, angle_type_map: Dict[Tuple[str, str, str], int], angle_types: List[AngleType], default_k_angle: float, default_theta0: float, fillers: Optional[Dict[str, List[str]]] = None) -> None
¶
Write the LAMMPS input script (in.polymer) for a bead-spring system.
Shared by BeadSpringPolymer (single species) and BeadSpringSystem (mixtures).
Note: For Kremer-Grest polymers using FENE bonds, the WCA cutoff (2^(1/6) * sigma ≈ 1.12246) should be used instead of full LJ cutoff (pair_style="wca"). The equilibrium bond length of ~0.97 emerges from the balance of FENE + WCA potentials - there is no explicit r0 in FENE.
fillers (motion -> filler atom-type ids) adds the CG-filler groups,
the held-filler minimization and rigid/frozen filler integration (see
AutoPoly.nanoparticles.cg); a pair coefficient may carry a third value,
its own cutoff.
Source code in AutoPoly/models/bead_spring.py
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 | |
Architectures (graph core)¶
AutoPoly.models.architectures
¶
Polymer Architecture Graph Core
This module provides the graph representation that underlies all bead-spring polymer architectures. A chain is described as an explicit graph:
- nodes = beads (each carrying a bead-type name)
- edges = bonds (explicit index pairs)
Linear chains, rings, stars, combs/grafts, tadpoles, dendrimers and arbitrary user-defined topologies are all the same kind of object; they differ only in their edge list. Everything downstream (bond/angle enumeration, SAW growth order, branched MC moves, data-file writing, mixtures) is derived from this single representation.
Two levels of construction are provided:
MonomerTemplate— a reusable multi-bead monomer unit (e.g. one backbone bead + one side-group bead) with named connection points ("head", "tail", "side"...). Architectures are assembled by connecting monomer instances through their named connection points.- Factory functions (
linear,ring,star,comb,graft,tadpole,dendrimer,custom) — convenient constructors returning bead-levelBeadArchitecturegraphs directly.
Copolymer sequence generators (block_sequence, alternating_sequence,
random_sequence, gradient_sequence) produce bead-type sequences that
can be used in any sequence slot (backbone, arm, side chain, ...).
Classes:
| Name | Description |
|---|---|
MonomerTemplate |
A reusable monomer unit: one or more beads with internal bonds and named |
BeadArchitecture |
Explicit bead-level graph of one polymer chain. |
Functions:
| Name | Description |
|---|---|
normalize_sequence |
Convert any supported sequence input to an explicit bead-type list. |
linear |
Linear chain: 0-1-2-...-(N-1). |
ring |
Ring (cyclic) chain: linear bonds + closure bond (N-1, 0). |
star |
Star polymer: one center bead with f arms. |
graft |
Graft/comb polymer with explicitly placed side chains. |
comb |
Regular comb polymer: identical side chains grafted every |
tadpole |
Tadpole (lariat) polymer: a ring with a linear tail attached. |
dendrimer |
Dendrimer / regularly branched polymer. |
custom |
Arbitrary user-defined architecture from an explicit bead list and |
block_sequence |
Block copolymer sequence: [("A", 50), ("B", 50)] -> A50-b-B50. |
alternating_sequence |
Alternating copolymer: types cycle along the chain ("ABABAB..."). |
random_sequence |
Statistical (random) copolymer sequence. |
gradient_sequence |
Gradient copolymer: probability of |
MonomerTemplate
dataclass
¶
A reusable monomer unit: one or more beads with internal bonds and named connection points.
Example — a graft monomer with one backbone bead and one side-group bead::
MonomerTemplate(
name="G",
beads=["A", "B"], # bead 0 = backbone, bead 1 = side
internal_bonds=[(0, 1)],
connections={"head": 0, "tail": 0, "side": 1},
)
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Template name (used to reference it in instance lists). |
beads |
List[str]
|
Bead type names, one per internal bead. |
internal_bonds |
List[Tuple[int, int]]
|
Bonds between internal beads (local indices). |
connections |
Dict[str, int]
|
Named connection points mapping a name ("head", "tail", "side", ...) to a local bead index. Inter-monomer bonds are defined between connection points. |
Methods:
| Name | Description |
|---|---|
single_bead |
Convenience: a single-bead monomer with connection points on the bead. |
Source code in AutoPoly/models/architectures.py
single_bead(bead_type: str, name: Optional[str] = None, connections: Tuple[str, ...] = ('head', 'tail')) -> MonomerTemplate
classmethod
¶
Convenience: a single-bead monomer with connection points on the bead.
Source code in AutoPoly/models/architectures.py
BeadArchitecture
dataclass
¶
Explicit bead-level graph of one polymer chain.
Attributes:
| Name | Type | Description |
|---|---|---|
bead_types |
List[str]
|
Bead type name per bead (node labels), length N. |
bonds |
List[Tuple[int, int]]
|
Explicit bond list as (i, j) bead index pairs, i != j. |
name |
str
|
Architecture name ("linear", "ring", "star", "comb", ...). |
Everything else — angle triplets, SAW growth order, MC subtree structure — is derived from these two lists.
Methods:
| Name | Description |
|---|---|
adjacency |
Adjacency list (sorted neighbor indices per bead). |
validate |
Validate the graph. |
angle_triplets |
All angle triplets as (i, j, k) with j the center bead. |
angle_triplets_classified |
Like :meth: |
growth_order |
DFS spanning-tree growth order from |
subtree_beyond_edge |
Beads reachable from |
linear_segments |
Maximal paths of degree-2 beads (plus their endpoints) suitable for |
from_monomers |
Expand monomer instances into a bead-level architecture. |
Source code in AutoPoly/models/architectures.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
is_branched: bool
property
¶
True if any bead has degree > 2 (star center, graft point, ...).
is_cyclic: bool
property
¶
True if the (connected) graph contains at least one cycle.
adjacency() -> List[List[int]]
¶
Adjacency list (sorted neighbor indices per bead).
Source code in AutoPoly/models/architectures.py
validate(known_bead_types: Optional[Sequence[str]] = None) -> None
¶
Validate the graph.
Checks: non-empty, bond indices in range, no duplicate/self bonds, connectedness, and (optionally) that all bead types are known.
Raises:
| Type | Description |
|---|---|
ValueError
|
On any violation. |
Source code in AutoPoly/models/architectures.py
angle_triplets(include_branch: bool = True) -> List[Tuple[int, int, int]]
¶
All angle triplets as (i, j, k) with j the center bead.
Enumerated by center bead in node order; for each center, all
neighbor pairs (i, k) with i < k. Triplets centered on a branch
point (degree > 2) are included only if include_branch is True.
For linear chains this yields exactly (i, i+1, i+2); for rings it additionally yields the wrap-around triplets — matching the legacy path-based enumeration.
Source code in AutoPoly/models/architectures.py
angle_triplets_classified(include_branch: bool = True) -> List[Tuple[Tuple[int, int, int], bool]]
¶
Like :meth:angle_triplets but returns ((i, j, k), is_branch) pairs,
where is_branch marks triplets centered on a branch point (degree > 2).
Source code in AutoPoly/models/architectures.py
growth_order(root: int = 0) -> Tuple[List[int], Dict[int, Optional[int]], List[Tuple[int, int]]]
¶
DFS spanning-tree growth order from root.
DFS (rather than BFS) keeps cycles as single long arcs with one closing edge at the far end — the same growth pattern as the legacy path-based ring SAW — which makes ring-closure constraints far easier to satisfy during placement. For trees (stars, combs, dendrimers) the spanning tree coincides with the full edge set either way.
Returns:
| Name | Type | Description |
|---|---|---|
order |
List[int]
|
Bead indices in placement order (each bead's parent appears before it). |
parents |
Dict[int, Optional[int]]
|
Map bead -> parent bead (None for root). |
closing_edges |
List[Tuple[int, int]]
|
Bonds not in the spanning tree (cycle-closing edges, e.g. the ring-closure bond). These are constraints to satisfy during placement rather than growth directions. |
Source code in AutoPoly/models/architectures.py
subtree_beyond_edge(u: int, v: int) -> List[int]
¶
Beads reachable from v without crossing the edge (u, v).
Cutting edge (u, v) splits the molecule; this returns the component
containing v. Used by the tree-pivot MC move: rotating this set
around any axis through bead u preserves the (u, v) bond length
and all internal bonds of the subtree.
Source code in AutoPoly/models/architectures.py
linear_segments(min_length: int = 3) -> List[List[int]]
¶
Maximal paths of degree-2 beads (plus their endpoints) suitable for crankshaft MC moves on branched architectures.
Returns:
| Type | Description |
|---|---|
List[List[int]]
|
List of bead-index paths, each of length >= min_length. For a |
List[List[int]]
|
linear chain this returns the whole chain as one segment. |
Source code in AutoPoly/models/architectures.py
from_monomers(templates: Dict[str, MonomerTemplate], instances: List[str], inter_bonds: List[Tuple[int, str, int, str]], name: str = 'custom') -> BeadArchitecture
classmethod
¶
Expand monomer instances into a bead-level architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
templates
|
Dict[str, MonomerTemplate]
|
Map template name -> MonomerTemplate. |
required |
instances
|
List[str]
|
Ordered list of template names (monomer instances). |
required |
inter_bonds
|
List[Tuple[int, str, int, str]]
|
Inter-monomer bonds as (instance_i, connection_i, instance_j, connection_j). |
required |
name
|
str
|
Architecture name. |
'custom'
|
Returns:
| Type | Description |
|---|---|
BeadArchitecture
|
BeadArchitecture with all internal + inter-monomer bonds. |
Example — three graft monomers polymerized head-to-tail::
BeadArchitecture.from_monomers(
templates={"G": graft_monomer},
instances=["G", "G", "G"],
inter_bonds=[(0, "tail", 1, "head"), (1, "tail", 2, "head")],
)
Source code in AutoPoly/models/architectures.py
normalize_sequence(seq: SequenceInput) -> List[str]
¶
Convert any supported sequence input to an explicit bead-type list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
SequenceInput
|
Sequence as string ("AABB"), explicit list (["A", "B"]), block format ([("A", 20), ("B", 10)]), or a single bare block tuple (("A", 20)). |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
Explicit list of bead type names. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sequence is empty or malformed. |
Source code in AutoPoly/models/architectures.py
linear(sequence: SequenceInput, name: str = 'linear') -> BeadArchitecture
¶
Linear chain: 0-1-2-...-(N-1).
Source code in AutoPoly/models/architectures.py
ring(sequence: SequenceInput, name: str = 'ring') -> BeadArchitecture
¶
Ring (cyclic) chain: linear bonds + closure bond (N-1, 0).
Source code in AutoPoly/models/architectures.py
star(center: str, arms: List[SequenceInput], name: str = 'star') -> BeadArchitecture
¶
Star polymer: one center bead with f arms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
str
|
Bead type of the center bead. |
required |
arms
|
List[SequenceInput]
|
List of arm sequences; arms may differ in length and composition (miktoarm / asymmetric stars). |
required |
Bead numbering: 0 = center; arm a occupies consecutive indices in the order given.
Source code in AutoPoly/models/architectures.py
graft(backbone: SequenceInput, grafts: Dict[int, SequenceInput], name: str = 'graft') -> BeadArchitecture
¶
Graft/comb polymer with explicitly placed side chains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone
|
SequenceInput
|
Backbone sequence. |
required |
grafts
|
Dict[int, SequenceInput]
|
Map backbone bead index -> side-chain sequence. A side chain may be a single bead (a literal "side group", e.g. "B") or an oligomer (e.g. [("B", 5)]). |
required |
Bead numbering: backbone beads 0..N-1, then side chains in order of sorted graft index.
Source code in AutoPoly/models/architectures.py
comb(backbone: SequenceInput, side: SequenceInput, every: int, offset: int = 0, name: str = 'comb') -> BeadArchitecture
¶
Regular comb polymer: identical side chains grafted every every
backbone beads, starting at offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone
|
SequenceInput
|
Backbone sequence. |
required |
side
|
SequenceInput
|
Side-chain sequence (single bead or oligomer). |
required |
every
|
int
|
Grafting spacing along the backbone. |
required |
offset
|
int
|
Backbone index of the first graft point. |
0
|
Source code in AutoPoly/models/architectures.py
tadpole(ring_seq: SequenceInput, tail: SequenceInput, attach: int = 0, name: str = 'tadpole') -> BeadArchitecture
¶
Tadpole (lariat) polymer: a ring with a linear tail attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ring_seq
|
SequenceInput
|
Ring sequence (beads 0..N-1, cyclically bonded). |
required |
tail
|
SequenceInput
|
Tail sequence, attached by its first bead to ring bead
|
required |
attach
|
int
|
Ring bead index where the tail attaches. |
0
|
Source code in AutoPoly/models/architectures.py
dendrimer(core: str, branch: str, branch_factor: int = 2, generations: int = 2, name: str = 'dendrimer') -> BeadArchitecture
¶
Dendrimer / regularly branched polymer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core
|
str
|
Bead type of the core bead. |
required |
branch
|
str
|
Bead type of all branch beads. |
required |
branch_factor
|
int
|
Number of children per node (core degree = branch_factor; internal branch beads have degree branch_factor + 1). |
2
|
generations
|
int
|
Number of branching shells. generations=1 gives a star with branch_factor arms of length 1. |
2
|
Source code in AutoPoly/models/architectures.py
custom(bead_types: List[str], bonds: List[Tuple[int, int]], name: str = 'custom') -> BeadArchitecture
¶
Arbitrary user-defined architecture from an explicit bead list and bond list (the escape hatch for topologies without a factory).
Source code in AutoPoly/models/architectures.py
block_sequence(blocks: List[Tuple[str, int]]) -> List[str]
¶
alternating_sequence(types: Sequence[str], n_beads: int) -> List[str]
¶
Alternating copolymer: types cycle along the chain ("ABABAB...").
Source code in AutoPoly/models/architectures.py
random_sequence(types: Sequence[str], n_beads: int, weights: Optional[Sequence[float]] = None, seed: Optional[int] = None) -> List[str]
¶
Statistical (random) copolymer sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
types
|
Sequence[str]
|
Bead type names to draw from. |
required |
n_beads
|
int
|
Chain length. |
required |
weights
|
Optional[Sequence[float]]
|
Sampling probability per type (uniform if None). |
None
|
seed
|
Optional[int]
|
Random seed for reproducibility. |
None
|
Source code in AutoPoly/models/architectures.py
gradient_sequence(type_start: str, type_end: str, n_beads: int, seed: Optional[int] = None) -> List[str]
¶
Gradient copolymer: probability of type_end grows linearly from 0
at the first bead to 1 at the last bead.
Source code in AutoPoly/models/architectures.py
Mixtures¶
AutoPoly.models.bead_spring_system
¶
Bead-Spring System (Mixtures)
This module provides BeadSpringSystem: a multi-species bead-spring melt builder. Each species is a (BeadArchitecture, n_chains) pair — linear chains, rings, stars, combs, or any custom graph can be mixed freely in one simulation box with one shared LAMMPS data file.
Example — a ring/linear blend::
from AutoPoly import System
from AutoPoly.models.bead_spring_system import BeadSpringSystem
from AutoPoly.models import architectures as arch
from AutoPoly.models.bead_spring import BeadType
system = System(out="ring_linear_blend")
bss = BeadSpringSystem(
name="blend",
system=system,
bead_types=[BeadType("A")],
bond_style="fene",
pair_style="wca",
density=0.85,
)
bss.add_species(arch.ring([("A", 50)]), n_chains=20)
bss.add_species(arch.linear([("A", 50)]), n_chains=20)
bss.generate_data_file()
Coarse-grained fillers (AutoPoly.nanoparticles.CGFiller) are added with
:meth:BeadSpringSystem.add_filler: they are placed first, chains grow
around them by SAW, and the run script integrates them as rigid bodies
(or keeps them frozen).
Classes:
| Name | Description |
|---|---|
BeadSpringSystem |
Multi-species bead-spring system (mixture) generator. |
BeadSpringSystem
¶
Multi-species bead-spring system (mixture) generator.
All species share one bead-type table, one box, and one LAMMPS data file. Chains are placed collision-free with the graph-based SAW generator; branched species are equilibrated with the branched MC moves (tree-pivot, segment crankshaft).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for output files. |
required |
system
|
object
|
System object containing path information. |
required |
bead_types
|
List[BeadType]
|
List of BeadType objects covering ALL bead types used by any species. |
required |
bond_length
|
float
|
Equilibrium bond length. |
1.0
|
bond_style
|
str
|
"harmonic" or "fene". |
'harmonic'
|
k_bond
|
float
|
Bond force constant. |
30.0
|
fene_r0
|
float
|
FENE maximum extension (only used if bond_style="fene"). |
1.5
|
pair_style
|
str
|
"lj" (full LJ, cutoff 2.5) or "wca" (repulsive). |
'lj'
|
use_angles
|
bool
|
Whether to include angle potentials. |
False
|
default_k_angle
|
float
|
Default angle force constant. |
10.0
|
default_theta0
|
float
|
Default equilibrium angle. |
180.0
|
angle_types
|
Optional[List[AngleType]]
|
Per-triplet AngleType parameters. |
None
|
include_branch_angles
|
bool
|
Whether to include angle triplets centered on branch points. |
True
|
density
|
Optional[float]
|
Target bead density (beads/sigma^3) for box sizing (with CG fillers: chain-bead density of the volume outside the filler envelopes). |
None
|
box_size
|
Optional[float]
|
Explicit box size (overrides density). |
None
|
generation_method
|
str
|
"geometric", "saw" (default), or "mc". |
'saw'
|
saw_config
|
Optional[SAWConfig]
|
SAW configuration. |
None
|
mc_config
|
Optional[MCConfig]
|
MC equilibration configuration. |
None
|
backend
|
str
|
Output backend used by :meth: |
'moltemplate'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters are invalid. |
Methods:
| Name | Description |
|---|---|
add_species |
Add a chain species to the mixture. |
add_filler |
Add a coarse-grained filler species (AutoPoly.nanoparticles.CGFiller). |
set_pair_coeff |
Override the Lorentz-Berthelot pair coefficients of one bead-type |
saw_generate |
Generate the mixture configuration using graph-based SAW. |
equilibrate |
Pre-equilibrate the mixture with Monte Carlo moves. |
generate |
Generate LAMMPS input files using the configured output backend. |
generate_data_file |
Generate the LAMMPS data file (and input script) for the mixture |
generate_moltemplate |
Generate moltemplate .lt files (and optionally run moltemplate) for |
get_system_info |
Get comprehensive information about the bead-spring mixture. |
Attributes:
| Name | Type | Description |
|---|---|---|
n_fillers |
int
|
Number of CG filler particles. |
Source code in AutoPoly/models/bead_spring_system.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | |
n_fillers: int
property
¶
Number of CG filler particles.
add_species(architecture: BeadArchitecture, n_chains: int, name: Optional[str] = None) -> None
¶
Add a chain species to the mixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
architecture
|
BeadArchitecture
|
BeadArchitecture of the chains. |
required |
n_chains
|
int
|
Number of chains of this species. |
required |
name
|
Optional[str]
|
Optional species label (defaults to the architecture name). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_chains < 1 or the architecture is invalid. |
Source code in AutoPoly/models/bead_spring_system.py
add_filler(filler) -> None
¶
Add a coarse-grained filler species (AutoPoly.nanoparticles.CGFiller).
Fillers are placed before the chains (random positions and
orientations, envelope gaps >= filler_min_gap); chains then
grow around them by SAW, so only generation_method="saw" is
supported. Filler beads are written as one molecule per particle.
Raises:
| Type | Description |
|---|---|
ValueError
|
Unknown filler bead type. |
Source code in AutoPoly/models/bead_spring_system.py
set_pair_coeff(type_a: str, type_b: str, epsilon: float, sigma: Optional[float] = None, cutoff: Optional[float] = None) -> None
¶
Override the Lorentz-Berthelot pair coefficients of one bead-type pair (e.g. the polymer-filler attraction), optionally with its own cutoff (e.g. an attractive 2.5 sigma pair in a WCA melt).
Source code in AutoPoly/models/bead_spring_system.py
saw_generate(saw_config: Optional[SAWConfig] = None) -> bool
¶
Generate the mixture configuration using graph-based SAW.
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise. |
Source code in AutoPoly/models/bead_spring_system.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
equilibrate(mc_config: Optional[MCConfig] = None) -> None
¶
Pre-equilibrate the mixture with Monte Carlo moves.
Branched chains use tree-pivot and segment-crankshaft moves; linear chains additionally use reptation.
Source code in AutoPoly/models/bead_spring_system.py
generate(backend: Optional[str] = None, run_moltemplate: bool = True) -> None
¶
Generate LAMMPS input files using the configured output backend.
This is the standard entry point for producing simulation files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Optional[str]
|
"moltemplate" (default; .lt files + moltemplate ->
moltemplate/system.data + system.in.*) or "direct"
(polymer.data + in.polymer written directly). Defaults to
the constructor's |
None
|
run_moltemplate
|
bool
|
Only for the moltemplate backend: run the bundled moltemplate after writing .lt files. |
True
|
Source code in AutoPoly/models/bead_spring_system.py
generate_data_file() -> None
¶
Generate the LAMMPS data file (and input script) for the mixture (direct backend).
Source code in AutoPoly/models/bead_spring_system.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
generate_moltemplate(run_moltemplate: bool = True) -> Path
¶
Generate moltemplate .lt files (and optionally run moltemplate) for this mixture.
Each chain becomes its own moltemplate object with generated coordinates; species share the bead-type table, so mixed systems (rings + stars + combs + ...) land in one system.data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_moltemplate
|
bool
|
Run the bundled moltemplate after writing files (produces system.data, system.in.init/settings). |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the moltemplate directory. |
Source code in AutoPoly/models/bead_spring_system.py
get_system_info() -> dict
¶
Get comprehensive information about the bead-spring mixture.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing system properties. |
Source code in AutoPoly/models/bead_spring_system.py
Moltemplate backend¶
AutoPoly.models.bead_spring_lt
¶
Moltemplate backend for bead-spring models.
Emits .lt files mirroring AutoPoly's atomistic pipeline conventions (monomer .lt objects, per-chain polymer .lt objects with explicit coordinates and "Data Bond List"/"Data Angles" sections, and a system.lt), then optionally runs the bundled moltemplate to produce system.data + system.in.init/settings.
Layout produced under <path>/moltemplate/::
bead_spring.lt CG force field: masses, styles, pair/bond/angle coeffs
bead_<Type>.lt one single-bead monomer object per bead type
chains.lt one object per chain: beads at generated coordinates
+ explicit bond list + typed angle list
fillers.lt (CG fillers only) one rigid particle object each
+ filler groups in "In Settings"
system.lt instantiates every chain + Data Boundary
in.polymer LAMMPS driver (includes system.in.init/settings)
Because coordinates are generated by the Python SAW/MC machinery before
.lt emission, arbitrary architectures (stars, combs, rings, mixtures)
work uniformly: the graph edge list becomes "Data Bond List" entries and
graph angle triplets become "Data Angles" entries with per-triplet
@angle: types (branch angles fully configurable).
Functions:
| Name | Description |
|---|---|
write_bead_spring_lt |
Write bead_spring.lt: the coarse-grained force-field object. |
write_bead_lt |
Write one single-bead monomer object for a bead type. |
write_chains_lt |
Write chains.lt: one moltemplate object per chain with beads at their |
write_fillers_lt |
Write fillers.lt: one object (one molecule ID) per placed CG filler |
write_system_lt |
Write system.lt: imports, one instance per chain (and CG filler), |
write_moltemplate_input_script |
Write in.polymer for the moltemplate backend. |
generate_moltemplate_files |
Generate all moltemplate .lt files for a bead-spring system and |
write_bead_spring_lt(filepath: Path, bead_types: List[BeadType], pair_coeffs: Dict[Tuple[int, int], Tuple[float, float]], bond_style: str, k_bond: float, bond_length: float, fene_r0: float, pair_style: str, use_angles: bool, angle_type_map: Dict[Tuple[str, str, str], int], resolve_angle_params: Callable[[Tuple[str, str, str]], Tuple[float, float]]) -> None
¶
Write bead_spring.lt: the coarse-grained force-field object.
Atom types are named @atom:<bead_name>; the single bond type is
@bond:bs1; angle types are @angle:at<id> per canonical triplet.
Source code in AutoPoly/models/bead_spring_lt.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
write_bead_lt(filepath: Path, bead_type: BeadType) -> None
¶
Write one single-bead monomer object for a bead type.
Source code in AutoPoly/models/bead_spring_lt.py
write_chains_lt(filepath: Path, chain_architectures: List[BeadArchitecture], positions: List[np.ndarray], chain_indices: List[Tuple[int, int]], use_angles: bool, angle_type_map: Dict[Tuple[str, str, str], int], include_branch_angles: bool, canonical_triplet: Callable[[str, str, str], Tuple[str, str, str]]) -> None
¶
Write chains.lt: one moltemplate object per chain with beads at their generated coordinates, explicit "Data Bond List" entries from the graph edge list, and typed "Data Angles" entries from graph triplets.
Source code in AutoPoly/models/bead_spring_lt.py
write_fillers_lt(filepath: Path, placed, groups: Dict[str, List[str]]) -> None
¶
Write fillers.lt: one object (one molecule ID) per placed CG filler
with its beads at world coordinates, plus the filler groups
(@atom: types resolved by moltemplate) in "In Settings".
Source code in AutoPoly/models/bead_spring_lt.py
write_system_lt(filepath: Path, n_chains: int, box_size: float, bead_type_names: List[str], n_fillers: int = 0) -> None
¶
Write system.lt: imports, one instance per chain (and CG filler), Data Boundary.
Source code in AutoPoly/models/bead_spring_lt.py
write_moltemplate_input_script(filepath: Path, fillers: Optional[Dict[str, List[str]]] = None) -> None
¶
Write in.polymer for the moltemplate backend.
Styles come from system.in.init and coeffs from system.in.settings
(both generated by moltemplate from bead_spring.lt). fillers
(motion -> bead types) adds the CG-filler run commands; the groups
themselves are defined in system.in.settings (fillers.lt).
Source code in AutoPoly/models/bead_spring_lt.py
generate_moltemplate_files(path: str, bead_types: List[BeadType], chain_architectures: List[BeadArchitecture], positions: List[np.ndarray], chain_indices: List[Tuple[int, int]], box_size: float, pair_coeffs: Dict[Tuple[int, int], Tuple[float, float]], bond_style: str, k_bond: float, bond_length: float, fene_r0: float, pair_style: str, use_angles: bool, angle_type_map: Dict[Tuple[str, str, str], int], resolve_angle_params: Callable[[Tuple[str, str, str]], Tuple[float, float]], include_branch_angles: bool, canonical_triplet: Callable[[str, str, str], Tuple[str, str, str]], run_moltemplate: bool = True, fillers: Optional[Tuple[list, Dict[str, List[str]]]] = None) -> Path
¶
Generate all moltemplate .lt files for a bead-spring system and optionally run moltemplate.
All structural information comes from the per-chain architectures (graph edge lists and angle triplets) and the generated coordinates, so arbitrary architectures and mixtures are supported uniformly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Project directory; files go under |
required |
bead_types
|
List[BeadType]
|
Shared bead type table. |
required |
chain_architectures
|
List[BeadArchitecture]
|
One BeadArchitecture per chain. |
required |
positions
|
List[ndarray]
|
Flat position list (global indexing). |
required |
chain_indices
|
List[Tuple[int, int]]
|
(start, end) per chain into |
required |
box_size
|
float
|
Cubic box side length. |
required |
pair_coeffs
|
Dict[Tuple[int, int], Tuple[float, float]]
|
Mixed pair coefficients (1-based type ids). |
required |
bond_style
|
str
|
"harmonic" or "fene". |
required |
k_bond
|
float
|
Bond force constant. |
required |
bond_length
|
float
|
Equilibrium bond length (harmonic). |
required |
fene_r0
|
float
|
FENE maximum extension. |
required |
pair_style
|
str
|
"lj" or "wca". |
required |
use_angles
|
bool
|
Whether angles are included. |
required |
angle_type_map
|
Dict[Tuple[str, str, str], int]
|
Canonical triplet -> angle type id. |
required |
resolve_angle_params
|
Callable[[Tuple[str, str, str]], Tuple[float, float]]
|
triplet -> (k, theta0). |
required |
include_branch_angles
|
bool
|
Whether branch triplets are included. |
required |
canonical_triplet
|
Callable[[str, str, str], Tuple[str, str, str]]
|
(t1, t2, t3) -> canonical triplet. |
required |
run_moltemplate
|
bool
|
Run the bundled moltemplate after writing files. |
True
|
fillers
|
Optional[Tuple[list, Dict[str, List[str]]]]
|
Optional (placed CG fillers, motion -> bead types) from AutoPoly.nanoparticles.cg. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the moltemplate directory. |
Raises:
| Type | Description |
|---|---|
WorkflowError
|
If moltemplate fails. |
Source code in AutoPoly/models/bead_spring_lt.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |