Registry / data / pynastran

pynastran

JSON →
library1.4.1pypypi✓ verified 89d ago

pyNastran is an open-source Python library for reading, editing, and writing Nastran BDF, OP2, OP4, and F06 files, commonly used in finite element analysis (FEA). It supports various Nastran versions and provides tools for visualizing and manipulating FEA data. The library is actively maintained, with version 1.4.1 being the latest stable release and a consistent release cadence.

pip install pynastran
INSTALL
IMPORT
SIG · PYNASTRAN
P
pynastran
datapythonv1.4.1
Install
13.9s avg
Import
1286ms
Disk
365MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 13.34s
py 3.11
✓ —
✓ 13.19s
py 3.12
✓ —
✓ 13.69s
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 15.35s
365MB installed
● package 365MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BDF
✓ from pyNastran.bdf.bdf import BDF
✗ from pynastran.bdf.bdf import BDF
The PyPI package is 'pynastran', but the internal module name uses 'pyNastran' capitalization.
OP2
✓ from pyNastran.op2.op2 import OP2
✗ from pynastran.op2.op2 import OP2
Consistent with the module capitalization for BDF, the module name is 'pyNastran'.
F06
✓ from pyNastran.f06.f06 import F06
F06 is for reading Nastran output listing files.

This quickstart demonstrates how to create a dummy BDF file, read it using the `BDF` class, and access basic model information like nodes and elements. The `xref=True` argument in `read_bdf` is highlighted as essential for properly populating the model with cross-referenced data.

import os from pyNastran.bdf.bdf import BDF # Create a dummy BDF file for demonstration bdf_content = """ SOL 101 CEND BEGIN BULK GRID,1,,0.0,0.0,0.0 GRID,2,,1.0,0.0,0.0 CQUAD4,1,1,1,2,3,4 ENDDATA """ dummy_bdf_path = "dummy.bdf" with open(dummy_bdf_path, "w") as f: f.write(bdf_content) # Read the BDF file model = BDF() try: # xref=True is crucial for resolving cross-references and building a complete model model.read_bdf(dummy_bdf_path, xref=True) print(f"Successfully read {dummy_bdf_path}") print(f"Number of GRIDs: {len(model.nodes)}") print(f"Number of CQUAD4 elements: {len(model.elements)}") # Accessing specific data (example) if 1 in model.nodes: print(f"Node 1 coordinates: {model.nodes[1].xyz}") except Exception as e: print(f"Error reading BDF file: {e}") finally: # Clean up the dummy file if os.path.exists(dummy_bdf_path): os.remove(dummy_bdf_path)
Debug
Known issues
gotchaThe PyPI package name is `pynastran` (lowercase 'p'), but the Python module and main classes use `pyNastran` (camel case 'P'). For example, you must use `from pyNastran.bdf.bdf import BDF`, not `from pynastran.bdf.bdf import BDF`.
fix
Ensure all imports use `pyNastran` with a capital 'N' after 'py'.
affects: All versions
gotchaWhen reading BDF files, failing to set `xref=True` in `model.read_bdf()` can lead to an incomplete model where cross-referenced entities (like elements referring to nodes) are not properly linked or even populated. This can result in empty dictionaries for elements, properties, etc.
fix
Always call `model.read_bdf('file.bdf', xref=True)` unless you explicitly need a non-cross-referenced model.
affects: All versions
gotchaLoading large Nastran OP2 result files can consume significant amounts of RAM, especially if the file contains many subcases, modes, or detailed output requests. Python's memory management combined with large numerical arrays can lead to performance issues or crashes.
fix
Consider only reading specific subcases or result types if possible, or process the data in chunks if the library supports it. Ensure sufficient RAM is available for the task.
affects: All versions
gotchaAccessing results from an `OP2` object can be complex due to its nested dictionary-like structure, often by subcase ID, result type, and sometimes mode. Directly indexing without checking for existence can lead to `KeyError`.
fix
Familiarize yourself with the `OP2` object's structure (e.g., `op2_model.get_op2_stats()`, `op2_model.op2_results`) and iterate through keys to find desired results. Use `if key in dict:` checks.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pynastran.bdf'
Attempting to import using the PyPI package name (`pynastran`) directly instead of the correct module name (`pyNastran`).
fix
Change your import statement from `from pynastran.bdf.bdf import BDF` to `from pyNastran.bdf.bdf import BDF` (note the capitalization).
KeyError: <some_element_id> (when trying to access elements or nodes from model.elements or model.nodes after reading a BDF)
The BDF model was read without resolving cross-references, leaving the `elements` or `nodes` dictionaries unpopulated or incomplete.
fix
Ensure you call `model.read_bdf('your_file.bdf', xref=True)` to populate all model entities and their relationships.
AttributeError: 'BDF' object has no attribute 'xyz'
You are trying to access coordinate data directly from the `BDF` model object, but coordinates are attributes of individual `Node` objects within `model.nodes`.
fix
Access node coordinates via `model.nodes[node_id].xyz`. For example, `model.nodes[1].xyz` for node ID 1.
ValueError: cannot find BDF object for card='XXXX' (where XXXX is a Nastran card type)
The BDF file contains a syntax error, an unsupported Nastran card type, or is corrupted, preventing pyNastran from parsing a specific line.
fix
Inspect the BDF file around the indicated card. Check for typos, incorrect formatting, or ensure the card type is supported by pyNastran for your Nastran version. Refer to Nastran documentation for correct card syntax.
Upgrade
Version history
1.4.1latest on PyPI · released Mar 26, 2024
Audit
Dependencies
numpyrequiredEssential for numerical operations and data structures.
scipyrequiredRequired for various scientific computing tasks, often used with numpy.
matplotliboptionalFor basic plotting functionalities of Nastran models and results.
Agent activity
8 hits · last 30 days
node
6
Resources
pynastran — pip install pynastran · libregistry