Package: rxiv-types
rxiv-types (v0.1.0)IntroductionA complete implementation of the XML/JSON schema for *Rxiv preprint servers. This
covers arXiv, medrXiv, biorXiv, chemrXiv, and DOAJ.This package helps to parse XML/JSON data into Pydantic models. This validates
the input xml data and provides typehints for working with the complex XML structures
present in PubMed data.Why do I need this?Parsing XML on its own is challenging. Add to it the feature rich data inside of each
citation, and you will find yourself with hours or days of navigating the XML structure.The approach here was to autogenerate Pydantic classes to parse the XML using thexsdata-pydantictool. This approach has the benefit of making sure every piece of data
is parsed properly, and an error is thrown if something is missing or incorrect. Instead
of using dictionaries to hold the data, Pydantic classes have the benefit of providing
type hints with tab completion for IDEs, making it easier to navigate the complex
structure of the citation data.How do I use it?It is possible to usexsdata-pydanticand the autogenerated classes directly to parse
an XML file, but we provide a convenience function to easily open PubMed XMl citations
and PMC open access articles.Example 1: Parse ChemRxiv DatafrompathlibimportPathimportrequestsfromrxiv_typesimportchemrxiv_recordschemrxiv_url="https://chemrxiv.org/engage/chemrxiv/public-api/v1/oai?verb=ListRecords&metadataPrefix=oai_dc&from=2000-01-01"# 1. Get some chemrxiv data from the APIresult=requests.get(chemrxiv_url)destination=Path(f"downloads/data/chemrxiv.xml")destination.parent.mkdir(parents=True,exist_ok=True)withopen(destination,"wb")asfw:fw.write(result.content)# 2. Parse the data, and display the first article titleresult=chemrxiv_records(destination)# 3. Print some information about the first recordprint("Paper 1:")print(f"Title:{''.join(result.list_records.record[0].metadata.dc.title)}")print(f"Authors:{'; '.join(result.list_records.record[0].metadata.dc.creator)}")print(f"Abstract:{''.join(result.list_records.record[0].metadata.dc.description)}")Output:Paper1:
Title:Excitonics:Auniversalsetofbinarygatesformolecularexcitonprocessingandsignaling
Authors:Nicolas,Sawaya;Dmitrij,Rappoport;Daniel,Tabor;Alan,Aspuru-Guzik
Abstract:Theabilitytoregulateenergytransferpathwaysthroughmaterialsisanimportantgoalofnanotechnology,asagreaterdegreeofcontroliscrucialfordevelopingsensing,solarenergy,andbioimagingapplications.Suchcontrolnecessitatesatoolboxofactuationmethodsthatcandirectenergytransferbasedonuserinput.Hereweproposeanovelmolecularexcitongate,analogoustoatraditionaltransistor,forcontrollingexcitonmigrationinchromophoricsystems.Thegatemaybeactivatedwithaninputoflightoraninputflowofexcitons.Unlikepreviousgatesandswitchesthatcontrolexcitontransfer,ourproposaldoesnotrequireisomerizationormolecularrearrangement,insteadrelyingonexcitationmigrationviathesecondsinglet(S2)stateofthegatemolecule--hencethesystemisnamedan"S2 exciton gate."AfterpresentingasetofsystempropertiesrequiredforproperfunctionoftheS2excitongate,weshowhowonewouldovercomethetwopossiblechallenges:short-livedexcitedstatesandsuppressionoffalsepositives.Precisionanderrorratesarestudiedcomputationallyinamodelsystemwithrespecttoexcited-statedecayratesandvariationsinmolecularorientation.Finally,wedemonstratethattheS2excitongategatecanbeusedtoproducebinarylogicalAND,OR,andNOToperations,providingauniversalexcitoniccomputationplatformwitharangeofpotentialapplications,includinge.g.insignalprocessingformicroscopy.FAQWhy are the return structures so complicated?The return structures are a direct reflection of the XML format defined by OAI and any
customizations from the hosting preprint servers. In the future some utility classes
might be made for common components (title, authors, etc), but for now this is intended
to be an unbiased way of parsing the XML.