{"id":47829326,"url":"https://github.com/basf/pytopas","last_synced_at":"2026-04-03T20:07:17.090Z","repository":{"id":69980346,"uuid":"463337268","full_name":"basf/pytopas","owner":"basf","description":"Bruker's TOPAS X-ray diffraction calculations parser","archived":false,"fork":false,"pushed_at":"2024-04-16T08:51:26.000Z","size":1151,"stargazers_count":5,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-14T00:06:05.275Z","etag":null,"topics":["materials-design","materials-informatics","materials-science","x-ray-diffraction","x-ray-images","x-ray-physics","x-ray-spectroscopy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-24T23:49:42.000Z","updated_at":"2024-05-14T00:06:07.625Z","dependencies_parsed_at":"2024-03-27T05:09:26.535Z","dependency_job_id":"65524c03-0a64-4dfa-8f86-61a00b61fdd7","html_url":"https://github.com/basf/pytopas","commit_stats":null,"previous_names":["metis-science/pytopas","tilde-lab/pytopas","basf/pytopas"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/basf/pytopas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basf%2Fpytopas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basf%2Fpytopas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basf%2Fpytopas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basf%2Fpytopas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basf","download_url":"https://codeload.github.com/basf/pytopas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basf%2Fpytopas/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31374101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["materials-design","materials-informatics","materials-science","x-ray-diffraction","x-ray-images","x-ray-physics","x-ray-spectroscopy"],"created_at":"2026-04-03T20:07:16.531Z","updated_at":"2026-04-03T20:07:17.071Z","avatar_url":"https://github.com/basf.png","language":"Python","readme":"# pytopas\n\nThis is an early version of Bruker's TOPAS macro language parser. This macro language is used by [commercial](https://www.bruker.com/de/products-and-solutions/diffractometers-and-x-ray-microscopes/x-ray-diffractometers/diffrac-suite-software.html) and [academic](http://www.topas-academic.net) TOPAS code. We have compared two canonical parsing approaches for Python, `lark` vs. `pyparsing`, and ended up with `pyparsing` being more convenient for debugging.\n\n\n## Installation\n\n`pip install .`\n\nInstall package with optional dependencies with `pip install -e .[lint,test,release]`\n\n\n## Usage\n\nParse a TOPAS macro language node with:\n\n```sh\necho \"xdd { 42 }\" | topas2json - | json2topas -\n```\n\nMore specifically, parse TOPAS input and convert it to JSON with:\n\n```python\nimport json\nfrom pytopas import TOPASParser\n\nsrc = \"a(b,c)\"\n\ntree = TOPASParser.parse(src)\nprint(json.dumps(tree))\n```\n\nConvert parser's JSON-encoded TOPAS code back into the TOPAS input format:\n\n```python\nimport json\nfrom pytopas import TOPASParseTree\n\ninput_json = \"\"\"\n[\"topas\",\n  [\"formula\",\n    [\"func_call\", \"a\",\n      [\"formula\", [\"p\", {\"n\": [\"parameter_name\", \"b\"]}]],\n      [\"formula\", [\"p\", {\"n\": [\"parameter_name\", \"c\"]}]]]]]\n\"\"\"\nserialized = json.loads(input_json)\nsrc = TOPASParser.reconstruct(serialized)\nprint(src)\n\n```\n\n\n## CLI\n\nAfter installing the package, two command line utilities will be available.\n\n```\nusage: topas2json [-h] [--ignore-warnings] file\n\nParse TOPAS input and output JSON\n\npositional arguments:\n  file               Path to TOPAS file or '-' for stdin input\n\noptions:\n  -h, --help         show this help message and exit\n  --ignore-warnings  Don't print parsing warnings\n```\n\n```\nusage: json2topas [-h] file\n\nParse JSON input and output TOPAS\n\npositional arguments:\n  file        Path to JSON file or '-' for stdin input\n\noptions:\n  -h, --help  show this help message and exit\n\n```\n\n\n## License\n\nAuthor Sergey Korolev, Tilde Materials Informatics\n\nCopyright 2023 BASF SE\n\nBSD 3-Clause\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasf%2Fpytopas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasf%2Fpytopas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasf%2Fpytopas/lists"}