{"id":21024,"library":"castepinput","title":"CASTEP Input File Parser/Writer","description":"A simple Python library for parsing and writing CASTEP input (.cell, .param) files. Current version 0.1.11, release cadence irregular.","status":"active","version":"0.1.11","language":"python","source_language":"en","source_url":"https://github.com/UCL-CCS/castepinput","tags":["CASTEP","input","parser","writer","materials science"],"install":[{"cmd":"pip install castepinput","lang":"bash","label":"Install castepinput"}],"dependencies":[],"imports":[{"note":"Common mistake: using CastepInputFile, correct class is CastepInput.","wrong":"from castepinput import CastepInputFile","symbol":"CastepInput","correct":"from castepinput import CastepInput"},{"note":"No common wrong import.","wrong":"","symbol":"write_cell","correct":"from castepinput import write_cell"}],"quickstart":{"code":"from castepinput import CastepInput\n\n# Parse an existing .cell file\nwith open('example.cell', 'r') as f:\n    content = f.read()\ncell = CastepInput(content)\nprint(cell.blocks)  # dict of blocks\n\n# Modify and write back\ncell.blocks['blockname'] = [['value1', 'value2']]\nwith open('output.cell', 'w') as f:\n    f.write(str(cell))","lang":"python","description":"Read a .cell file, modify a block, and write it back."},"warnings":[{"fix":"Read the file first: with open('path.cell') as f: content = f.read() then CastepInput(content)","message":"CastepInput accepts file content as a string, not a file path. Use open().read() to pass content.","severity":"gotcha","affected_versions":"all"},{"fix":"Assign directly to `cell.blocks['blockname'] = new_list_of_lists`","message":"Block values are stored as lists of lists; modifying direct list may not update the internal representation. Use the provided methods if available.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use cell.blocks.items() to iterate over blocks and their values.","cause":"Trying to iterate over a CastepInput object directly; blocks must be accessed via .blocks attribute.","error":"TypeError: argument of type 'CastepInput' is not iterable"},{"fix":"Read the file content with open('file.cell').read() before passing to CastepInput.","cause":"Passing a file path string to CastepInput constructor instead of file content.","error":"AttributeError: 'str' object has no attribute 'keys'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}