File size: 25,939 Bytes
e73ce34 | 1 2 3 4 5 6 7 8 9 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 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 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 | from __future__ import annotations
import pytest
from app.modules.cdk_depict.annotations import (
AnnotationSystem,
AnnotationMode,
MAPPING_COLORS,
)
from app.modules.toolkits.cdk_wrapper import get_CDK_IAtomContainer
from jpype import JClass
@pytest.fixture
def annotation_system():
return AnnotationSystem()
@pytest.fixture
def simple_molecule():
return get_CDK_IAtomContainer("CCO")
@pytest.fixture
def chiral_molecule():
return get_CDK_IAtomContainer("C[C@H](O)CC")
@pytest.fixture
def complex_molecule():
return get_CDK_IAtomContainer("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
class TestAnnotationSystemInitialization:
"""Test annotation system initialization."""
def test_default_initialization(self):
system = AnnotationSystem()
assert system.cdk_base == "org.openscience.cdk"
def test_annotation_system_has_required_attributes(self):
system = AnnotationSystem()
assert hasattr(system, "StandardGenerator")
assert hasattr(system, "Color")
assert hasattr(system, "CDKConstants")
class TestAnnotationModes:
"""Test different annotation modes."""
def test_none_mode_no_annotations(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NONE
)
assert gen is not None
def test_number_mode(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
assert gen is not None
def test_bondnumber_mode(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.BONDNUMBER
)
assert gen is not None
def test_mapidx_mode(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.MAPIDX
)
assert gen is not None
def test_atomvalue_mode(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.ATOMVALUE
)
assert gen is not None
def test_colmap_mode(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.COLMAP
)
assert gen is not None
def test_cip_mode(self, annotation_system, chiral_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, chiral_molecule, AnnotationMode.CIP
)
assert gen is not None
class TestAtomNumbering:
"""Test atom numbering annotations."""
def test_apply_atom_numbers(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
assert gen is not None
def test_atom_numbers_on_complex_molecule(
self, annotation_system, complex_molecule
):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, complex_molecule, AnnotationMode.NUMBER
)
assert gen is not None
def test_atom_numbers_with_aromatic(self, annotation_system):
mol = get_CDK_IAtomContainer("c1ccccc1")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.NUMBER
)
assert gen is not None
class TestBondNumbering:
"""Test bond numbering annotations."""
def test_apply_bond_numbers(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.BONDNUMBER
)
assert gen is not None
def test_bond_numbers_on_complex_molecule(
self, annotation_system, complex_molecule
):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, complex_molecule, AnnotationMode.BONDNUMBER
)
assert gen is not None
class TestMappingAnnotations:
"""Test atom mapping annotations."""
def test_apply_map_indices(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.MAPIDX
)
assert gen is not None
def test_colored_mapping(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.COLMAP
)
assert gen is not None
def test_mapping_with_reaction_molecule(self, annotation_system):
mol = get_CDK_IAtomContainer("C([H:1])([H:2])([H:3])[H:4]")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.MAPIDX
)
assert gen is not None
class TestAtomValueAnnotations:
"""Test atom value annotations."""
def test_apply_atom_values(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.ATOMVALUE
)
assert gen is not None
def test_atom_values_on_complex_molecule(self, annotation_system, complex_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, complex_molecule, AnnotationMode.ATOMVALUE
)
assert gen is not None
class TestCIPAnnotations:
"""Test CIP stereochemistry annotations."""
def test_apply_cip_on_chiral_molecule(self, annotation_system, chiral_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, chiral_molecule, AnnotationMode.CIP
)
assert gen is not None
def test_cip_on_simple_molecule(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.CIP
)
assert gen is not None
def test_cip_on_ez_stereochemistry(self, annotation_system):
mol = get_CDK_IAtomContainer("C/C=C/C")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.CIP
)
assert gen is not None
def test_cip_on_multiple_chiral_centers(self, annotation_system):
mol = get_CDK_IAtomContainer("C[C@H](O)[C@@H](C)Cl")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.CIP
)
assert gen is not None
class TestMappingColors:
"""Test mapping color constants."""
def test_mapping_colors_defined(self):
assert isinstance(MAPPING_COLORS, list)
assert len(MAPPING_COLORS) > 0
def test_mapping_colors_contain_indices(self):
# MAPPING_COLORS is a list where index represents the mapping number
for idx in range(1, 10): # Start from 1 since 0 is None
assert idx < len(MAPPING_COLORS)
assert MAPPING_COLORS[idx] is not None
def test_mapping_colors_are_tuples(self):
# Each color (except index 0) should be an RGB tuple
for idx in range(1, len(MAPPING_COLORS)):
color = MAPPING_COLORS[idx]
assert isinstance(color, tuple)
assert len(color) == 3 # RGB
# Verify values are in valid range
for component in color:
assert 0 <= component <= 255
class TestApplyAnnotationsIntegration:
"""Test apply_annotations method integration."""
def test_apply_number_annotation(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
assert gen is not None
def test_apply_bond_annotation(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.BONDNUMBER
)
assert gen is not None
def test_apply_cip_annotation(self, annotation_system, chiral_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, chiral_molecule, AnnotationMode.CIP
)
assert gen is not None
def test_apply_mapidx_annotation(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.MAPIDX
)
assert gen is not None
def test_apply_colmap_annotation(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.COLMAP
)
assert gen is not None
class TestEdgeCases:
"""Test edge cases and boundary conditions."""
def test_single_atom_molecule(self, annotation_system):
mol = get_CDK_IAtomContainer("C")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.NUMBER
)
assert gen is not None
def test_disconnected_fragments(self, annotation_system):
mol = get_CDK_IAtomContainer("CCO.C1CCOC1")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.NUMBER
)
assert gen is not None
def test_aromatic_molecule(self, annotation_system):
mol = get_CDK_IAtomContainer("c1ccccc1")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.NUMBER
)
assert gen is not None
def test_charged_molecule(self, annotation_system):
mol = get_CDK_IAtomContainer("[NH4+]")
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen = annotation_system.apply_annotations(
DepictionGenerator, mol, AnnotationMode.NUMBER
)
assert gen is not None
class TestAnnotationPersistence:
"""Test that annotations can be applied and changed."""
def test_multiple_annotation_modes(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen1 = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
gen2 = annotation_system.apply_annotations(
gen1, simple_molecule, AnnotationMode.BONDNUMBER
)
assert gen2 is not None
def test_annotation_change(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen1 = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
gen2 = annotation_system.apply_annotations(
gen1, simple_molecule, AnnotationMode.CIP
)
assert gen2 is not None
def test_remove_annotations(self, annotation_system, simple_molecule):
DepictionGenerator = JClass("org.openscience.cdk.depict.DepictionGenerator")()
gen1 = annotation_system.apply_annotations(
DepictionGenerator, simple_molecule, AnnotationMode.NUMBER
)
gen2 = annotation_system.apply_annotations(
gen1, simple_molecule, AnnotationMode.NONE
)
assert gen2 is not None
class TestGetAnnotationMode:
"""Test the get_annotation_mode helper function."""
def test_valid_mode_number(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("number")
assert mode == AnnotationMode.NUMBER
def test_valid_mode_bondnumber(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("bondnumber")
assert mode == AnnotationMode.BONDNUMBER
def test_valid_mode_mapidx(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("mapidx")
assert mode == AnnotationMode.MAPIDX
def test_valid_mode_atomvalue(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("atomvalue")
assert mode == AnnotationMode.ATOMVALUE
def test_valid_mode_colmap(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("colmap")
assert mode == AnnotationMode.COLMAP
def test_valid_mode_cip(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("cip")
assert mode == AnnotationMode.CIP
def test_valid_mode_none(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("none")
assert mode == AnnotationMode.NONE
def test_valid_mode_with_whitespace(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode(" number ")
assert mode == AnnotationMode.NUMBER
def test_valid_mode_case_insensitive(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
mode = get_annotation_mode("NUMBER")
assert mode == AnnotationMode.NUMBER
def test_invalid_mode_raises_valueerror(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
with pytest.raises(ValueError) as exc_info:
get_annotation_mode("invalid_mode")
assert "Invalid annotation mode" in str(exc_info.value)
assert "valid_mode" not in str(exc_info.value).lower() or "Valid modes" in str(
exc_info.value
)
def test_invalid_mode_lists_valid_modes(self):
from app.modules.cdk_depict.annotations import get_annotation_mode
with pytest.raises(ValueError) as exc_info:
get_annotation_mode("xyz")
error_msg = str(exc_info.value)
assert "none" in error_msg
assert "number" in error_msg
assert "cip" in error_msg
class TestApplyAnnotationsConvenience:
"""Test the module-level apply_annotations convenience function."""
def test_apply_annotations_number_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="number")
assert result is not None
def test_apply_annotations_none_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="none")
assert result is not None
def test_apply_annotations_cip_mode(self, chiral_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, chiral_molecule, mode="cip")
assert result is not None
def test_apply_annotations_invalid_mode_returns_generator(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="invalid_mode")
# Should return unmodified generator on error
assert result is not None
def test_apply_annotations_mapidx_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="mapidx")
assert result is not None
def test_apply_annotations_bondnumber_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="bondnumber")
assert result is not None
def test_apply_annotations_atomvalue_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="atomvalue")
assert result is not None
def test_apply_annotations_colmap_mode(self, simple_molecule):
from app.modules.cdk_depict.annotations import (
apply_annotations as apply_annotations_func,
)
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = apply_annotations_func(gen, simple_molecule, mode="colmap")
assert result is not None
class TestAtomValueAnnotationsWithValues:
"""Test atom value annotations when atoms have actual values set."""
def test_atom_values_with_comment_property(self, annotation_system):
"""Test annotating atoms that have COMMENT property set."""
mol = get_CDK_IAtomContainer("CCO")
CDKConstants = JClass("org.openscience.cdk.CDKConstants")
# Set COMMENT property on atoms
for i, atom in enumerate(mol.atoms()):
atom.setProperty(CDKConstants.COMMENT, f"val{i}")
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, mol, AnnotationMode.ATOMVALUE)
assert result is not None
def test_atom_values_without_comment_property(self, annotation_system):
"""Test annotating atoms that have no COMMENT property."""
mol = get_CDK_IAtomContainer("CCO")
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, mol, AnnotationMode.ATOMVALUE)
assert result is not None
class TestColorMappingWithMappedAtoms:
"""Test color mapping when atoms actually have mapping numbers."""
def test_color_mapping_with_mapped_atoms(self, annotation_system):
"""Test colmap mode with atoms that have atom-atom mapping."""
mol = get_CDK_IAtomContainer("[CH3:1][OH:2]")
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, mol, AnnotationMode.COLMAP)
assert result is not None
def test_color_mapping_with_various_map_indices(self, annotation_system):
"""Test colmap mode with various mapping indices within MAPPING_COLORS range."""
mol = get_CDK_IAtomContainer("[C:1]([H:2])([H:3])[O:4][H:5]")
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, mol, AnnotationMode.COLMAP)
assert result is not None
class TestAnnotationExceptionPaths:
"""Test error handling paths in annotation system."""
def test_apply_annotations_with_error_returns_generator(self, annotation_system):
"""Test that apply_annotations returns generator even on internal error."""
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
# Pass None molecule - should trigger exception and return generator
result = annotation_system.apply_annotations(
gen, None, AnnotationMode.ATOMVALUE
)
assert result is not None
def test_annotate_atom_values_exception_path(self, annotation_system):
"""Test _annotate_atom_values exception handling."""
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(
gen, None, AnnotationMode.ATOMVALUE
)
assert result is not None
def test_annotate_color_mapping_exception_path(self, annotation_system):
"""Test _annotate_color_mapping exception handling."""
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, None, AnnotationMode.COLMAP)
assert result is not None
def test_annotate_cip_exception_path(self, annotation_system):
"""Test _annotate_cip exception handling."""
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(gen, None, AnnotationMode.CIP)
assert result is not None
def test_is_reaction_with_non_reaction_object(self, annotation_system):
"""Test _is_reaction with a non-reaction object."""
mol = get_CDK_IAtomContainer("CCO")
assert annotation_system._is_reaction(mol) is False
def test_is_reaction_with_none(self, annotation_system):
"""Test _is_reaction with None."""
assert annotation_system._is_reaction(None) is False
class TestReactionAnnotations:
"""Test annotation modes on reaction objects."""
def _create_reaction(self):
"""Helper to create a simple CDK reaction."""
Reaction = JClass("org.openscience.cdk.Reaction")
reaction = Reaction()
reactant = get_CDK_IAtomContainer("CCO")
product = get_CDK_IAtomContainer("CC=O")
reaction.addReactant(reactant)
reaction.addProduct(product)
return reaction
def test_atomvalue_on_reaction(self, annotation_system):
"""Test atom value annotation on reaction objects."""
reaction = self._create_reaction()
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(
gen, reaction, AnnotationMode.ATOMVALUE
)
assert result is not None
def test_colmap_on_reaction(self, annotation_system):
"""Test color mapping annotation on reaction objects."""
reaction = self._create_reaction()
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(
gen, reaction, AnnotationMode.COLMAP, is_reaction=True
)
assert result is not None
def test_cip_on_reaction(self, annotation_system):
"""Test CIP annotation on reaction objects."""
reaction = self._create_reaction()
gen = JClass("org.openscience.cdk.depict.DepictionGenerator")()
result = annotation_system.apply_annotations(
gen, reaction, AnnotationMode.CIP, is_reaction=True
)
assert result is not None
def test_is_reaction_with_actual_reaction(self, annotation_system):
"""Test _is_reaction correctly identifies IReaction objects."""
reaction = self._create_reaction()
assert annotation_system._is_reaction(reaction) is True
|