materials
Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.
FoSpy.blocks.materials
Chemical
Bases: SingleBlock
An abbreviated reference to a material, product, or chemical composition.
This class is the bare minimum for identifying a chemical composition.
Additional requirements are enforced for various subclasses, including
Material and Product.
Source code in FoSpy/blocks/chemicals.py
add_MW
Attach a comment to the formula with molecular weight.
Source code in FoSpy/blocks/chemicals.py
Debug
Source code in FoSpy/_debug.py
__init__
_get_text_width
Source code in FoSpy/_debug.py
msg
Source code in FoSpy/_debug.py
pmsg
Source code in FoSpy/_debug.py
ListBlock
Bases: Block
Represents multiple similar blocks of key:value pairs parsed from a FOS File
ListBlocks are used to group multiple SingleBlocks of the same subclass
together and define methods that modify or access information from multiple
SingleBlocks at once. SingleBlocks contained within a ListBlock can be
indexed and iterated over directly instead of calling ListBlock._objs
Attributes:
| Name | Type | Description |
|---|---|---|
_objs |
List containing the stored |
|
_reqCls |
type[SingleBlock]
|
Specifies which |
Notable Subclasses:
MaterialList(ListBlock) # Contains Material(SingleBlock) objects
TreamentList(ListBlock) # Contains Treatment(SingleBlock) objects
Source code in FoSpy/blocks/blocks.py
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 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 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 2166 2167 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 | |
Simple
classmethod
Creates a simple subclass of ListBlock
Creates a subclass of ListBlock that only accepts objects of the
specified SingleBlock subclass.
Simple ListBlocks are used when no specialized methods or attributes are needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reqCls
|
The subclass of |
SingleBlock
|
Source code in FoSpy/blocks/blocks.py
TemplateClass
__eq__
Check equality of two ListBlock objects.
Equality is checked by a deep difference of their serialized lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
The other |
required | |
suppress_routine_paths
|
Optional flag to still return true if the only differences found are in calculation routine metadata. Calculation routines are for user information only and may not be relevant for equality. |
False
|
Source code in FoSpy/blocks/blocks.py
__getitem__
Get an item from this ListBlock by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
The index of the item |
required |
__hash__
__init__
Constructs a ListBlock from a list of objects or serialized dictionaries.
Each item in blockList is checked against the SingleBlock subclass
specified for the ListBlock subclass. If the item is not the correct
subclass, it is passed to the SingleBlock subclass's
dispatch_subclass method for coersion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blockList
|
list
|
A list containing either |
required |
Raises:
TypeError:
ListBlock instances can only be constructed from subclasses with an assigned _reqCls, not the parent ListBlock class.
Source code in FoSpy/blocks/blocks.py
__iter__
__len__
__setattr__
Only private attributes starting with "_" can be set.
Items in self._objs can be edited/replaced individually by indexing with
self[i], or self._objs can be replaced with a new list, which is
re-validated and coerced to the correct SingleBlock subclass specified
by _reqCls
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
The name of the attribute to set. |
required | |
value
|
The value to set the attribute to. |
required |
Raises:
AttributeError:
Only private attributes starting with "_" can be set.
TypeError:
self._objs must be a list of objects which can be coerced to the
correct SingleBlock subclass specified by _reqCls
Source code in FoSpy/blocks/blocks.py
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 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 | |
__setitem__
Set an item to this ListBlock by index.
After setting, all items in this ListBlock's _objs list are passed
back to __setattr__ for
validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
The index of the item |
required | |
val
|
The new value for the item |
required |
Source code in FoSpy/blocks/blocks.py
add_dispatch
classmethod
Source code in FoSpy/blocks/blocks.py
append
Append a SingleBlock-coercable object to this ListBlock
Appends the object to this ListBlock's _objs list, and passes the
entire list back to
__setattr__ for
validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
SingleBlock
|
The object to append |
required |
Source code in FoSpy/blocks/blocks.py
block_to_idx
Source code in FoSpy/blocks/blocks.py
clear_all_comments
copy
default_key_order
fill_staged_template
Source code in FoSpy/blocks/blocks.py
get_any
Source code in FoSpy/blocks/blocks.py
get_first
get_idx
has_staged
insert
Insert a SingleBlock-coercable object into this ListBlock.
Inserts the object into this ListBlock's _objs list, and passes the
entire list back to
__setattr__ for
validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
The index to insert the object at |
required | |
obj
|
SingleBlock
|
The object to insert |
required |
Source code in FoSpy/blocks/blocks.py
list_avail_routines
Lists all methods decorated as calc routines.
Methods are resolved as path strings relative to self, including
indexing for recursively searched methods within self._objs. When
returned back to a parent ListBlock object's call, these strings
produce paths that can be resolved back into function calls relative to
the parent object. See SingleBlock.list_avail_routines().
This method is usually only used in a recursive call from a
SingleBlock object where one of its attributes is a ListBlock.
Example:
mySyn.materals.list_avail_routines(recursive=True)
## returns [
## 'add_weight_pcts',
## '[0].add_MW',
## '[1].add_MW',
## ... 6 total materials with the same calc_routine
## '[5].add_MW'
## ]
# Resursive call from `SingleBlock` mySyn object:
mySyn.list_avail_routines(recursive=True)
## returns [
## 'reaction.add_nom_MW',
## 'materials.add_weight_pcts',
## 'materials[0].add_MW',
## 'materials[1].add_MW',
## ... 6 total materials with the same calc_routine
## 'materials[5].add_MW'
## ]
Source code in FoSpy/blocks/blocks.py
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 | |
order_down
order_up
refresh_attachments
Source code in FoSpy/blocks/blocks.py
remove_any
Remove any objects from self._objs with attributes matching kwargs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
A single keyword argument can be passed. Any objects with attr:value matching kw:arg are removed. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
Exactly one keyword argument is required. |
Example:
mySyn.materials.remove_any(supplier="sigma")
## removes any obj from mySyn.materials._objs where
## obj.supplier == "sigma"
Source code in FoSpy/blocks/blocks.py
remove_block
remove_idx
Remove a range of items from this ListBlock
Removes a range of items from this ListBlock's _objs list, and
passes the entire list back to
__setattr__ for
validation.
from_idx is inclusive, and to_idx is non-inclusive. i.e., if
from_idx is 0 and to_idx is 1, then the first item in the list will
be removed, but not the second.
If from_idx is None, then all items starting at and including to_idx
will be removed. If to_idx is None, then all items up to and not
including from_idx will be removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_idx
|
int
|
The index of the first item to remove |
None
|
to_idx
|
int
|
The non-inclusive index to stop removing |
None
|
Source code in FoSpy/blocks/blocks.py
serialize
Serialize this ListBlock as a list of dictionaries.
Overriding list type is only skipped when all objects in the list have
the same list type. To prevent mutation, list type override is performed
by calling
set_list_type on a copy
of this ListBlock and returning the serialized copy.
ListBlocks of length one are always overridden to "explicit".
List Types
- "explicit": Each object declares its own keys.
- "looped": Common keys are declared once at the beginning of a list. Each object specifies values for those keys in the declared order. Anomalous keys are still printed as key:value pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clean
|
When True, no FOS format read/write metadata is included in the serial. Recommended for sending output to other formats like JSON. |
False
|
|
shallow
|
When True, no recursive serialization occurs. Recommended when serialization is used only to inspect top-level keys for object dictionaries. |
False
|
|
override_list_type
|
str | bool
|
|
None
|
Source code in FoSpy/blocks/blocks.py
set_list_type
Set FOS list formatting (explicit or looped).
Sets metadata for all items in this ListBlock to the specified type.
List Types
- "explicit": Each object declares its own keys.
- "looped": Common keys are declared once at the beginning of a list. Each object specifies values for those keys in the declared order. Anomalous keys are still printed as key:value pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
The type to set |
'explicit'
|
Source code in FoSpy/blocks/blocks.py
stage_template
Source code in FoSpy/blocks/blocks.py
Material
MaterialList
Bases: ListBlock
Represents a list of materials used in a synthesis
Source code in FoSpy/blocks/materials.py
add_all_MW
add_weight_pcts
Calculate weight percents and attach them as comments to each material's amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
Only materials with type attribute matching typ are considered in the total weight and given weight percents. This is useful if, for instance, you want weight percents of your contributing "reagents" without including "flux" or "solvent" materials. |
None
|
Source code in FoSpy/blocks/materials.py
calc_weight_pcts
Calculate weight percent for each material with matching type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
Only materials with type attribute matching typ are considered in the total weight and given weight percents. This is useful if, for instance, you want weight percents of your contributing "reagents" without including "flux" or "solvent" materials. |
None
|
Returns:
| Type | Description |
|---|---|
|
dict mapping material : weight_pct |
Source code in FoSpy/blocks/materials.py
_calc_routine
Decorator for SingleBlock or ListBlock methods that calculate values
from existing attributes.
calc_routine functions can be called at any time, but can also be queued
to run at serialization, as in refreshing relevant calculated values before
saving the file. See SingleBlock.add_calc_routine()