Validator Module
validator.parser_manager
ParserException
dataclass
Bases: Exception
Exception for parser errors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule
|
str
|
The rule that caused the error. |
required |
parameter
|
str
|
The parameter that caused the error. |
required |
message
|
str
|
The error message. |
required |
Source code in src/validator/parser_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
ParserManager
Parser manager to parse the SMILES strings.
Attributes:
Name | Type | Description |
---|---|---|
current_open_rnum |
The current open ring numbers. |
|
current_closed_rnum |
The current closed ring numbers. |
|
current_chain |
list[Atom]
|
The current chain. |
Source code in src/validator/parser_manager.py
38 39 40 41 42 43 44 45 46 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 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 |
|
__enter__
__enter__()
Initializes the parser manager.
Source code in src/validator/parser_manager.py
52 53 54 55 56 57 |
|
atom
atom(symbol_or_bracket: str)
Parses the atom symbol or bracket and from this point on always returns the parser manager Args: symbol_or_bracket: The atom symbol or bracket atom. Returns: The atom
Source code in src/validator/parser_manager.py
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 |
|
charge
charge(charge1: str, charge2: Union[str, None, int]) -> int
Parsers the charge string to an integer. Args: charge1: either "+" or "-". charge2: either "+", "-", None or an integer. Returns: The parsed charge as an integer.
Source code in src/validator/parser_manager.py
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 |
|
chiral
chiral(chiral1: str, chiral2: Optional[str]) -> str
Fixes the current chiral rotation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chiral1
|
str
|
The first chiral symbol. |
required |
chiral2
|
Optional[str]
|
The second chiral symbol, if any. |
required |
Returns: The current chiral rotation.
Source code in src/validator/parser_manager.py
307 308 309 310 311 312 313 314 315 316 317 318 |
|
fifteen
fifteen(digit1: str, digit2: Optional[str]) -> int
Fixes fifteen as maximum value for valency Args: digit1: The first digit to be parsed. digit2: The second digit to be parsed, if any. Returns: The parsed rules.
Source code in src/validator/parser_manager.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
hcount
hcount(_, digit: Optional[str]) -> int
Parses the hydrogen count. Args: digit: The digit to be parsed. Returns: The parsed hydrogen count.
Source code in src/validator/parser_manager.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
inner_branch
inner_branch(bond_dot=None, line=None, inner_branch=None)
Source code in src/validator/parser_manager.py
91 92 93 94 95 96 97 |
|
int
int(digits: List[str]) -> int
Parses the provided digits to an integer. Args: digits: The digits to be parsed. Returns: The parsed integer.
Source code in src/validator/parser_manager.py
248 249 250 251 252 253 254 255 256 |
|
internal_bracket
internal_bracket(istope, symbol, chiral, hcount, charge, mol_map)
Parses the internal bracket and checks for valency.
Source code in src/validator/parser_manager.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
listify
listify(base_element, recursion)
Generic rule for dealing with rules in the following format:
x -> y x x -> y Args: base_element: Base element. recursion: The chain element. Returns: The parsed atom or chain branch.
Source code in src/validator/parser_manager.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
ring_number
ring_number(ring_number_or_symbol: str, ring_number1: Optional[str], ring_number2: Optional[str]) -> int
Parses the ring numbers provided. Args: ring_number_or_symbol: A number or the % symbol. ring_number1: The first digit, if any. ring_number2: The second digit, if any. Returns: The parsed ring number as an integer.
Source code in src/validator/parser_manager.py
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 |
|
validate_branch
validate_branch() -> bool
Validates based on the current state of the parser manager
Source code in src/validator/parser_manager.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
fill_none
fill_none(func)
Decorator to fill None values in the function arguments
Source code in src/validator/parser_manager.py
8 9 10 11 12 13 14 15 16 17 18 19 |
|
validator.yacc
SmilesParser
Bases: Parser
Parser using the SLY library to parse SMILES strings.
Source code in src/validator/yacc.py
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 |
|
generate_combinations
generate_combinations(rule: str) -> list[str]
Generate all combinations of a rule with optional elements. Example: rule = "X? Y Z?" combinations = [ X Y Z, X Y, Y Z, Y ]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule
|
str
|
A string with the rule to generate combinations from. |
required |
Returns: A list of strings with all combinations of the rule.
Source code in src/validator/yacc.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
getAttributes
getAttributes(rules, properties)
Get the attributes of the rules. Args: rules: The rules to get the attributes from. properties: The properties to get the attributes from. Returns: The attributes of the rules.
Source code in src/validator/yacc.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
validate_smiles
validate_smiles(mol: str) -> tuple[bool, Exception | None]
Function for valdiating a SMILES molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol
|
str
|
Chemical formula as a string. |
required |
use_only_grammar
|
For valdiating only the Grammar |
required |
Returns:
Type | Description |
---|---|
tuple[bool, Exception | None]
|
A Tuple containg in the first element if it is a valid SMILES and the second element a Exception. |
Source code in src/validator/yacc.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
validator.lex
SmilesLex
Bases: Lexer
Tokenizer for SMILES strings.
Attributes:
Name | Type | Description |
---|---|---|
tokens |
A set of all tokens |
|
literals |
A set of all literals |
|
semi_symbol |
A regex for semi symbols |
|
semi_bond |
A regex for semi bonds |
|
digit |
A regex for digits |
Source code in src/validator/lex.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
generate_lower
generate_lower(elem_list: list[str]) -> list[str]
Generate a list of lower case elements from a list of elements and return both the lower and upper case elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elem_list
|
list[str]
|
A list of elements to generate a lower case list from. |
required |
Returns: A list with all elements.
Source code in src/validator/lex.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
generate_regex_from_list
generate_regex_from_list(elem_list: list[str]) -> str
Generate a regex from a list of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elem_list
|
list[str]
|
A list of elements to generate a regex from. |
required |
Returns: A regex string that matches any of the elements in the list.
Source code in src/validator/lex.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|