55import tempfile
66import pytest
77import biotite .database .afdb as afdb
8+ import biotite .database .rcsb as rcsb
89import biotite .structure .io .pdb as pdb
910import biotite .structure .io .pdbx as pdbx
1011from biotite .database import RequestError
1516
1617@pytest .mark .skipif (cannot_connect_to (AFDB_URL ), reason = "AlphaFold DB is not available" )
1718@pytest .mark .parametrize ("as_file_like" , [False , True ])
18- @pytest .mark .parametrize ("entry_id" , ["P12345" , "AF-P12345-F1" , "AF-P12345F1" ])
19+ @pytest .mark .parametrize (
20+ "entry_id" , ["P12345" , "AF-P12345-F1" , "AF-P12345F1" , "AF_AFP12345F1" ]
21+ )
1922@pytest .mark .parametrize ("format" , ["pdb" , "cif" , "bcif" ])
2023def test_fetch (as_file_like , entry_id , format ):
2124 """
2225 Check if files in different formats can be downloaded by being able to parse them.
2326 Also ensure that the downloaded file refers to the given input ID
2427 """
2528 path = None if as_file_like else tempfile .gettempdir ()
26- file_path_or_obj = afdb .fetch (entry_id , format , path , overwrite = True )
29+ try :
30+ file_path_or_obj = afdb .fetch (entry_id , format , path , overwrite = True )
31+ except RequestError :
32+ pytest .skip ("AFDB is probably busy" )
2733 if format == "pdb" :
2834 file = pdb .PDBFile .read (file_path_or_obj )
2935 pdb .get_structure (file )
@@ -37,6 +43,34 @@ def test_fetch(as_file_like, entry_id, format):
3743 assert file .block ["struct_ref" ]["pdbx_db_accession" ].as_item () == "P12345"
3844
3945
46+ def test_fetch_cross_id ():
47+ """
48+ Test if :func:`afdb.fetch()` works with AlphaFold DB cross-references
49+ in search results from :func:`rcsb.search()`.
50+ """
51+ UNIPROT_ID = "P12345"
52+
53+ ids = rcsb .search (
54+ rcsb .FieldQuery (
55+ "rcsb_entry_info.structure_determination_methodology" ,
56+ exact_match = "computational" ,
57+ )
58+ & rcsb .FieldQuery (
59+ "rcsb_polymer_entity_container_identifiers"
60+ ".reference_sequence_identifiers"
61+ ".database_accession" ,
62+ exact_match = UNIPROT_ID ,
63+ ),
64+ content_types = ("computational" ,),
65+ )
66+ assert len (ids ) == 1
67+ try :
68+ pdbx_file = pdbx .CIFFile .read (afdb .fetch (ids [0 ], "cif" ))
69+ except RequestError :
70+ pytest .skip ("AFDB is probably busy" )
71+ assert pdbx_file .block ["struct_ref" ]["pdbx_db_accession" ].as_item () == UNIPROT_ID
72+
73+
4074@pytest .mark .skipif (cannot_connect_to (AFDB_URL ), reason = "AlphaFold DB is not available" )
4175def test_fetch_multiple ():
4276 """
0 commit comments