PyGamLab 1.2.2__tar.gz → 1.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PKG-INFO +1 -1
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Primatom/__init__.py +2 -2
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Primatom/gam_molecule.py +2 -2
- pygamlab-1.2.2/PyGamLab/structures/Primatom/gam_atom.py → pygamlab-1.2.3/PyGamLab/structures/Primatom/gam_universe.py +426 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab.egg-info/PKG-INFO +1 -1
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab.egg-info/SOURCES.txt +1 -2
- {pygamlab-1.2.2 → pygamlab-1.2.3}/pyproject.toml +1 -1
- {pygamlab-1.2.2 → pygamlab-1.2.3}/setup.py +1 -1
- pygamlab-1.2.2/PyGamLab/structures/Primatom/gam_bond.py +0 -570
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/Constants.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/Converters.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/Data_Analysis.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/Functions.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_Graphene.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_nano_particles.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_nanotubes.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_phosphorene.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_sillicene.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Generators/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Generators/auto_bulk.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Generators/one_d.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Generators/two_d.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/Generators/zero_d.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/gamvis/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/gamvis/gamvis.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/gamvis/gamvis_engine.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/io/__init__.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/io/checker.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/io/conversions.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/io/export.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/io/read.py +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab.egg-info/dependency_links.txt +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab.egg-info/requires.txt +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab.egg-info/top_level.txt +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/README.md +0 -0
- {pygamlab-1.2.2 → pygamlab-1.2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyGamLab
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: A scientific Python library with constants, unit convertors, formulas, and data analysis tools.
|
|
5
5
|
Home-page: https://github.com/APMaii/pygamlab/tree/main
|
|
6
6
|
Author: Ali Pilehvar Meibody
|
|
@@ -746,6 +746,432 @@ class GAM_Atom:
|
|
|
746
746
|
|
|
747
747
|
|
|
748
748
|
|
|
749
|
+
|
|
750
|
+
class GAM_Bond:
|
|
751
|
+
"""
|
|
752
|
+
Advanced bond class for computational chemistry and molecular modeling applications.
|
|
753
|
+
|
|
754
|
+
The GAM_Bond class represents covalent bonds between atoms within molecular systems
|
|
755
|
+
and provides comprehensive functionality for structural analysis, geometric calculations,
|
|
756
|
+
and bond property evaluation. It supports various bond orders, strain energy calculations,
|
|
757
|
+
and advanced geometric transformations essential for molecular dynamics simulations
|
|
758
|
+
and quantum chemistry computations.
|
|
759
|
+
|
|
760
|
+
Attributes:
|
|
761
|
+
id (int): Unique identifier for the bond within a molecular system.
|
|
762
|
+
atom1_id (int): ID of the first atom in the bond.
|
|
763
|
+
atom2_id (int): ID of the second atom in the bond.
|
|
764
|
+
order (int): Bond order (1=single, 2=double, 3=triple).
|
|
765
|
+
_length (Optional[float]): Cached bond length in Angstroms.
|
|
766
|
+
_energy (Optional[float]): Cached bond energy in Joules.
|
|
767
|
+
|
|
768
|
+
Examples:
|
|
769
|
+
Basic bond creation:
|
|
770
|
+
>>> bond = GAM_Bond(id=1, atom1_id=1, atom2_id=2, order=1)
|
|
771
|
+
>>> print(f"Bond order: {bond.order}")
|
|
772
|
+
Bond order: 1
|
|
773
|
+
|
|
774
|
+
Bond length calculation:
|
|
775
|
+
>>> atoms = {1: GAM_Atom(1, "C", 0.0, 0.0, 0.0),
|
|
776
|
+
... 2: GAM_Atom(2, "C", 1.54, 0.0, 0.0)}
|
|
777
|
+
>>> bond = GAM_Bond(1, 1, 2, 1)
|
|
778
|
+
>>> length = bond.calculate_length(atoms)
|
|
779
|
+
>>> print(f"Bond length: {length:.2f} Å")
|
|
780
|
+
Bond length: 1.54 Å
|
|
781
|
+
|
|
782
|
+
Bond validation:
|
|
783
|
+
>>> is_reasonable = bond.is_reasonable_length(atoms)
|
|
784
|
+
>>> print(f"Reasonable bond length: {is_reasonable}")
|
|
785
|
+
Reasonable bond length: True
|
|
786
|
+
|
|
787
|
+
Strain energy calculation:
|
|
788
|
+
>>> strain_energy = bond.calculate_strain_energy(atoms)
|
|
789
|
+
>>> print(f"Strain energy: {strain_energy:.3f} kcal/mol")
|
|
790
|
+
Strain energy: 0.000 kcal/mol
|
|
791
|
+
|
|
792
|
+
Notes:
|
|
793
|
+
- Bond lengths are calculated in Angstroms.
|
|
794
|
+
- Strain energies are calculated in kcal/mol using harmonic approximation.
|
|
795
|
+
- Bond validation uses reference bond lengths with 20% tolerance.
|
|
796
|
+
- All geometric calculations require access to the complete atom dictionary.
|
|
797
|
+
|
|
798
|
+
Raises:
|
|
799
|
+
ValueError: If fixed atom ID in rotation operations is not part of the bond.
|
|
800
|
+
ValueError: If atoms associated with the bond do not exist in the provided dictionary.
|
|
801
|
+
|
|
802
|
+
See Also:
|
|
803
|
+
GAM_Atom: For individual atom representation and properties.
|
|
804
|
+
GAM_Molecule: For complete molecular system management.
|
|
805
|
+
REFERENCE_BOND_LENGTHS: For reference bond length data.
|
|
806
|
+
"""
|
|
807
|
+
|
|
808
|
+
def __init__(self, id: int, atom1_id: int, atom2_id: int, order: int = 1):
|
|
809
|
+
self.id = id
|
|
810
|
+
self.atom1_id = atom1_id
|
|
811
|
+
self.atom2_id = atom2_id
|
|
812
|
+
self.order = order
|
|
813
|
+
self._length: Optional[float] = None
|
|
814
|
+
self._energy: Optional[float] = None
|
|
815
|
+
|
|
816
|
+
@property
|
|
817
|
+
def bond_vector(self, atoms: Dict[int, GAM_Atom]) -> np.ndarray:
|
|
818
|
+
"""Calculate the bond vector from atom1 to atom2."""
|
|
819
|
+
atom1 = atoms[self.atom1_id]
|
|
820
|
+
atom2 = atoms[self.atom2_id]
|
|
821
|
+
return atom2.position - atom1.position
|
|
822
|
+
|
|
823
|
+
def calculate_length(self, atoms: Dict[int, GAM_Atom]) -> float:
|
|
824
|
+
"""Calculate the bond length in Angstroms."""
|
|
825
|
+
return np.linalg.norm(self.bond_vector(atoms))
|
|
826
|
+
|
|
827
|
+
def is_reasonable_length(self, atoms: Dict[int, GAM_Atom]) -> bool:
|
|
828
|
+
"""
|
|
829
|
+
Check if the bond length is reasonable based on reference data.
|
|
830
|
+
|
|
831
|
+
Args:
|
|
832
|
+
atoms: Dictionary mapping atom IDs to Atom objects
|
|
833
|
+
|
|
834
|
+
Returns:
|
|
835
|
+
bool: True if the bond length is within 20% of reference value
|
|
836
|
+
"""
|
|
837
|
+
atom1 = atoms[self.atom1_id]
|
|
838
|
+
atom2 = atoms[self.atom2_id]
|
|
839
|
+
|
|
840
|
+
# Sort elements to match reference data format
|
|
841
|
+
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
842
|
+
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
843
|
+
ref_length = ref_lengths.get(str(self.order))
|
|
844
|
+
|
|
845
|
+
if ref_length is None:
|
|
846
|
+
return True # No reference data available
|
|
847
|
+
|
|
848
|
+
actual_length = self.calculate_length(atoms)
|
|
849
|
+
return abs(actual_length - ref_length) / ref_length < 0.2
|
|
850
|
+
|
|
851
|
+
#maybe mroe reliable:
|
|
852
|
+
def is_reasonable_length(self, atoms: Dict[int, GAM_Atom]) -> bool:
|
|
853
|
+
"""
|
|
854
|
+
Check if the bond length is reasonable based on reference data.
|
|
855
|
+
...
|
|
856
|
+
"""
|
|
857
|
+
atom1 = atoms[self.atom1_id]
|
|
858
|
+
atom2 = atoms[self.atom2_id]
|
|
859
|
+
|
|
860
|
+
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
861
|
+
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
862
|
+
# Corrected lookup to use integer key
|
|
863
|
+
ref_length = ref_lengths.get(self.order)
|
|
864
|
+
|
|
865
|
+
if ref_length is None:
|
|
866
|
+
return True
|
|
867
|
+
|
|
868
|
+
actual_length = self.calculate_length(atoms)
|
|
869
|
+
return abs(actual_length - ref_length) / ref_length < 0.2
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
def calculate_angle_with(self, other: 'GAM_Bond', atoms: Dict[int, GAM_Atom]) -> float:
|
|
875
|
+
"""
|
|
876
|
+
Calculate angle between this bond and another bond.
|
|
877
|
+
|
|
878
|
+
Args:
|
|
879
|
+
other: Another Bond object
|
|
880
|
+
atoms: Dictionary mapping atom IDs to Atom objects
|
|
881
|
+
|
|
882
|
+
Returns:
|
|
883
|
+
float: Angle in degrees between the bonds
|
|
884
|
+
"""
|
|
885
|
+
v1 = self.bond_vector(atoms)
|
|
886
|
+
v2 = other.bond_vector(atoms)
|
|
887
|
+
cos_angle = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
|
|
888
|
+
return np.degrees(np.arccos(np.clip(cos_angle, -1.0, 1.0)))
|
|
889
|
+
|
|
890
|
+
def rotate_around_axis(self,
|
|
891
|
+
axis: np.ndarray,
|
|
892
|
+
angle_degrees: float,
|
|
893
|
+
atoms: Dict[int, GAM_Atom],
|
|
894
|
+
fixed_atom_id: Optional[int] = None) -> None:
|
|
895
|
+
"""
|
|
896
|
+
Rotate the bond around an axis while keeping one atom fixed.
|
|
897
|
+
|
|
898
|
+
Args:
|
|
899
|
+
axis: Rotation axis
|
|
900
|
+
angle_degrees: Rotation angle in degrees
|
|
901
|
+
atoms: Dictionary mapping atom IDs to Atom objects
|
|
902
|
+
fixed_atom_id: ID of the atom to keep fixed (defaults to atom1_id)
|
|
903
|
+
"""
|
|
904
|
+
if fixed_atom_id is None:
|
|
905
|
+
fixed_atom_id = self.atom1_id
|
|
906
|
+
|
|
907
|
+
if fixed_atom_id not in {self.atom1_id, self.atom2_id}:
|
|
908
|
+
raise ValueError(f"Fixed atom ID must be either {self.atom1_id} or {self.atom2_id}.")
|
|
909
|
+
|
|
910
|
+
moving_atom_id = self.atom2_id if fixed_atom_id == self.atom1_id else self.atom1_id
|
|
911
|
+
|
|
912
|
+
# Get the fixed atom's position as rotation center
|
|
913
|
+
center = atoms[fixed_atom_id].position
|
|
914
|
+
|
|
915
|
+
# Rotate the moving atom
|
|
916
|
+
atoms[moving_atom_id].rotate_around_axis(axis, angle_degrees, center)
|
|
917
|
+
|
|
918
|
+
def calculate_strain_energy(self, atoms: Dict[int, GAM_Atom]) -> float:
|
|
919
|
+
"""
|
|
920
|
+
Calculate the strain energy of the bond based on deviation from ideal length.
|
|
921
|
+
|
|
922
|
+
Args:
|
|
923
|
+
atoms: Dictionary mapping atom IDs to Atom objects
|
|
924
|
+
|
|
925
|
+
Returns:
|
|
926
|
+
float: Strain energy in kcal/mol
|
|
927
|
+
"""
|
|
928
|
+
atom1 = atoms[self.atom1_id]
|
|
929
|
+
atom2 = atoms[self.atom2_id]
|
|
930
|
+
|
|
931
|
+
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
932
|
+
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
933
|
+
ref_length = ref_lengths.get(str(self.order))
|
|
934
|
+
|
|
935
|
+
if ref_length is None:
|
|
936
|
+
return 0.0
|
|
937
|
+
|
|
938
|
+
actual_length = self.calculate_length(atoms)
|
|
939
|
+
# Simple harmonic approximation
|
|
940
|
+
force_constant = 100.0 # kcal/mol/Ų (approximate)
|
|
941
|
+
return 0.5 * force_constant * (actual_length - ref_length) ** 2
|
|
942
|
+
|
|
943
|
+
def get_elements(self, atoms: Dict[int, 'GAM_Atom']) -> Tuple[str, str]:
|
|
944
|
+
"""
|
|
945
|
+
Returns a tuple of the elements involved in the bond.
|
|
946
|
+
|
|
947
|
+
Args:
|
|
948
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
949
|
+
|
|
950
|
+
Returns:
|
|
951
|
+
A sorted tuple of the elements (e.g., ('C', 'H')).
|
|
952
|
+
"""
|
|
953
|
+
atom1 = atoms[self.atom1_id]
|
|
954
|
+
atom2 = atoms[self.atom2_id]
|
|
955
|
+
return tuple(sorted([atom1.element, atom2.element]))
|
|
956
|
+
|
|
957
|
+
def get_bond_type(self, atoms: Dict[int, 'GAM_Atom']) -> str:
|
|
958
|
+
"""
|
|
959
|
+
Returns a descriptive string for the bond type.
|
|
960
|
+
|
|
961
|
+
Args:
|
|
962
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
963
|
+
|
|
964
|
+
Returns:
|
|
965
|
+
A string describing the bond (e.g., 'C-C single bond').
|
|
966
|
+
"""
|
|
967
|
+
elements = self.get_elements(atoms)
|
|
968
|
+
bond_order_map = {1: 'single', 2: 'double', 3: 'triple'}
|
|
969
|
+
bond_type = bond_order_map.get(self.order, 'unspecified')
|
|
970
|
+
return f"{elements[0]}-{elements[1]} {bond_type} bond"
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
def is_aromatic(self, atoms: Dict[int, 'GAM_Atom']) -> bool:
|
|
975
|
+
"""
|
|
976
|
+
Checks if the bond is likely part of an aromatic system.
|
|
977
|
+
This is a simple heuristic based on bond order and element types.
|
|
978
|
+
|
|
979
|
+
Args:
|
|
980
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
981
|
+
|
|
982
|
+
Returns:
|
|
983
|
+
True if the bond is aromatic, False otherwise.
|
|
984
|
+
"""
|
|
985
|
+
if self.order == 1:
|
|
986
|
+
elements = self.get_elements(atoms)
|
|
987
|
+
# Aromatic bonds are often C-C bonds with an order of 1.5,
|
|
988
|
+
# but in some representations, they are labeled as order 1.
|
|
989
|
+
if elements == ('C', 'C'):
|
|
990
|
+
# Check for a more subtle indicator of aromaticity, such as sp2 hybridization
|
|
991
|
+
atom1 = atoms[self.atom1_id]
|
|
992
|
+
atom2 = atoms[self.atom2_id]
|
|
993
|
+
# A common heuristic is checking if both atoms have 3 neighbors
|
|
994
|
+
if len(atom1._bonds) == 3 and len(atom2._bonds) == 3:
|
|
995
|
+
return True
|
|
996
|
+
return False
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
def calculate_dihedral_angle(self, atom3_id: int, atom4_id: int, atoms: Dict[int, 'GAM_Atom']) -> float:
|
|
1000
|
+
"""
|
|
1001
|
+
Calculates the dihedral angle between this bond and a plane defined by
|
|
1002
|
+
the third and fourth atoms.
|
|
1003
|
+
|
|
1004
|
+
Args:
|
|
1005
|
+
atom3_id: The ID of the third atom.
|
|
1006
|
+
atom4_id: The ID of the fourth atom.
|
|
1007
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
1008
|
+
|
|
1009
|
+
Returns:
|
|
1010
|
+
The dihedral angle in degrees.
|
|
1011
|
+
"""
|
|
1012
|
+
atom1 = atoms[self.atom1_id]
|
|
1013
|
+
atom2 = atoms[self.atom2_id]
|
|
1014
|
+
atom3 = atoms[atom3_id]
|
|
1015
|
+
atom4 = atoms[atom4_id]
|
|
1016
|
+
|
|
1017
|
+
b1 = atom1.position - atom2.position
|
|
1018
|
+
b2 = atom3.position - atom2.position
|
|
1019
|
+
b3 = atom4.position - atom3.position
|
|
1020
|
+
|
|
1021
|
+
n1 = np.cross(b1, b2)
|
|
1022
|
+
n2 = np.cross(b2, b3)
|
|
1023
|
+
|
|
1024
|
+
m1 = np.cross(n1, b2 / np.linalg.norm(b2))
|
|
1025
|
+
|
|
1026
|
+
x = np.dot(n1, n2)
|
|
1027
|
+
y = np.dot(m1, n2)
|
|
1028
|
+
|
|
1029
|
+
return np.degrees(np.arctan2(y, x))
|
|
1030
|
+
|
|
1031
|
+
def calculate_angle_with_plane(self, plane_normal: np.ndarray, atoms: Dict[int, 'GAM_Atom']) -> float:
|
|
1032
|
+
"""
|
|
1033
|
+
Calculates the angle between the bond vector and a user-defined plane.
|
|
1034
|
+
|
|
1035
|
+
Args:
|
|
1036
|
+
plane_normal: The normal vector of the plane.
|
|
1037
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
1038
|
+
|
|
1039
|
+
Returns:
|
|
1040
|
+
The angle in degrees.
|
|
1041
|
+
"""
|
|
1042
|
+
bond_vector = self.bond_vector(atoms)
|
|
1043
|
+
normal_vec = plane_normal / np.linalg.norm(plane_normal)
|
|
1044
|
+
|
|
1045
|
+
# The angle between the vector and the normal of the plane
|
|
1046
|
+
cos_angle_to_normal = np.dot(bond_vector, normal_vec) / (np.linalg.norm(bond_vector))
|
|
1047
|
+
|
|
1048
|
+
# The angle with the plane is 90 degrees minus the angle with the normal
|
|
1049
|
+
angle_with_plane_rad = np.pi / 2 - np.arccos(np.clip(cos_angle_to_normal, -1.0, 1.0))
|
|
1050
|
+
|
|
1051
|
+
return np.degrees(angle_with_plane_rad)
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
1056
|
+
"""
|
|
1057
|
+
Serializes the bond's data into a dictionary.
|
|
1058
|
+
|
|
1059
|
+
Returns:
|
|
1060
|
+
A dictionary representation of the bond.
|
|
1061
|
+
"""
|
|
1062
|
+
return {
|
|
1063
|
+
'id': self.id,
|
|
1064
|
+
'atom1_id': self.atom1_id,
|
|
1065
|
+
'atom2_id': self.atom2_id,
|
|
1066
|
+
'order': self.order
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
def get_atoms(self, atoms: Dict[int, 'GAM_Atom']) -> Tuple['GAM_Atom', 'GAM_Atom']:
|
|
1070
|
+
"""
|
|
1071
|
+
Retrieves the two GAM_Atom objects connected by this bond.
|
|
1072
|
+
|
|
1073
|
+
Args:
|
|
1074
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
1075
|
+
|
|
1076
|
+
Returns:
|
|
1077
|
+
A tuple containing the two GAM_Atom objects.
|
|
1078
|
+
"""
|
|
1079
|
+
atom1 = atoms.get(self.atom1_id)
|
|
1080
|
+
atom2 = atoms.get(self.atom2_id)
|
|
1081
|
+
if not all([atom1, atom2]):
|
|
1082
|
+
raise ValueError("One or more atoms associated with this bond do not exist.")
|
|
1083
|
+
return atom1, atom2
|
|
1084
|
+
|
|
1085
|
+
def get_neighboring_bonds(self, atoms: Dict[int, 'GAM_Atom']) -> List['GAM_Bond']:
|
|
1086
|
+
"""
|
|
1087
|
+
Finds all other bonds that share an atom with this bond.
|
|
1088
|
+
|
|
1089
|
+
Args:
|
|
1090
|
+
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
1091
|
+
|
|
1092
|
+
Returns:
|
|
1093
|
+
A list of GAM_Bond objects that are neighbors to this bond.
|
|
1094
|
+
"""
|
|
1095
|
+
atom1, atom2 = self.get_atoms(atoms)
|
|
1096
|
+
neighboring_bonds = []
|
|
1097
|
+
for bond in atom1.get_bonds():
|
|
1098
|
+
if bond.id != self.id:
|
|
1099
|
+
neighboring_bonds.append(bond)
|
|
1100
|
+
for bond in atom2.get_bonds():
|
|
1101
|
+
if bond.id != self.id and bond not in neighboring_bonds:
|
|
1102
|
+
neighboring_bonds.append(bond)
|
|
1103
|
+
return neighboring_bonds
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
def is_part_of_ring(self, atoms: Dict[int, 'GAM_Atom'], max_ring_size: int = 7) -> bool:
|
|
1108
|
+
"""
|
|
1109
|
+
Checks if the bond is part of a closed ring structure using Breadth-First Search (BFS).
|
|
1110
|
+
...
|
|
1111
|
+
"""
|
|
1112
|
+
atom1, atom2 = self.get_atoms(atoms)
|
|
1113
|
+
|
|
1114
|
+
# Use a more efficient deque for the queue
|
|
1115
|
+
queue = deque([(atom2, 1, {atom2.id})]) # (current_atom, path_length, visited_set)
|
|
1116
|
+
|
|
1117
|
+
while queue:
|
|
1118
|
+
current_atom, path_length, visited = queue.popleft()
|
|
1119
|
+
|
|
1120
|
+
if path_length >= max_ring_size:
|
|
1121
|
+
continue
|
|
1122
|
+
|
|
1123
|
+
for bond in current_atom.get_bonds():
|
|
1124
|
+
if bond.id == self.id:
|
|
1125
|
+
continue
|
|
1126
|
+
|
|
1127
|
+
neighbor = atoms[bond.atom2_id if bond.atom1_id == current_atom.id else bond.atom1_id]
|
|
1128
|
+
|
|
1129
|
+
if neighbor.id == atom1.id:
|
|
1130
|
+
return True # Found a path back to atom1, forming a ring
|
|
1131
|
+
|
|
1132
|
+
if neighbor.id not in visited:
|
|
1133
|
+
new_visited = visited.copy()
|
|
1134
|
+
new_visited.add(neighbor.id)
|
|
1135
|
+
queue.append((neighbor, path_length + 1, new_visited))
|
|
1136
|
+
return False
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
@classmethod
|
|
1141
|
+
def from_dict(cls, data: Dict[str, Any]) -> 'GAM_Bond':
|
|
1142
|
+
"""
|
|
1143
|
+
Reconstructs a GAM_Bond object from a dictionary.
|
|
1144
|
+
|
|
1145
|
+
Args:
|
|
1146
|
+
data: A dictionary containing the bond's data.
|
|
1147
|
+
|
|
1148
|
+
Returns:
|
|
1149
|
+
A new GAM_Bond object.
|
|
1150
|
+
"""
|
|
1151
|
+
return cls(
|
|
1152
|
+
id=data['id'],
|
|
1153
|
+
atom1_id=data['atom1_id'],
|
|
1154
|
+
atom2_id=data['atom2_id'],
|
|
1155
|
+
order=data['order']
|
|
1156
|
+
)
|
|
1157
|
+
|
|
1158
|
+
def to_json(self, filepath: str):
|
|
1159
|
+
"""
|
|
1160
|
+
Saves the bond's data to a JSON file.
|
|
1161
|
+
|
|
1162
|
+
Args:
|
|
1163
|
+
filepath: The path to the output JSON file.
|
|
1164
|
+
"""
|
|
1165
|
+
with open(filepath, 'w') as f:
|
|
1166
|
+
json.dump(self.to_dict(), f, indent=4)
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
def __repr__(self) -> str:
|
|
1171
|
+
return f"Bond(id={self.id}, atom1_id={self.atom1_id}, atom2_id={self.atom2_id}, order={self.order})"
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
749
1175
|
|
|
750
1176
|
|
|
751
1177
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyGamLab
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: A scientific Python library with constants, unit convertors, formulas, and data analysis tools.
|
|
5
5
|
Home-page: https://github.com/APMaii/pygamlab/tree/main
|
|
6
6
|
Author: Ali Pilehvar Meibody
|
|
@@ -24,9 +24,8 @@ PyGamLab/structures/Generators/one_d.py
|
|
|
24
24
|
PyGamLab/structures/Generators/two_d.py
|
|
25
25
|
PyGamLab/structures/Generators/zero_d.py
|
|
26
26
|
PyGamLab/structures/Primatom/__init__.py
|
|
27
|
-
PyGamLab/structures/Primatom/gam_atom.py
|
|
28
|
-
PyGamLab/structures/Primatom/gam_bond.py
|
|
29
27
|
PyGamLab/structures/Primatom/gam_molecule.py
|
|
28
|
+
PyGamLab/structures/Primatom/gam_universe.py
|
|
30
29
|
PyGamLab/structures/gamvis/__init__.py
|
|
31
30
|
PyGamLab/structures/gamvis/gamvis.py
|
|
32
31
|
PyGamLab/structures/gamvis/gamvis_engine.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PyGamLab"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.3"
|
|
8
8
|
description = "A scientific Python library with constants, unit convertors, formulas, and data analysis tools."
|
|
9
9
|
authors = [
|
|
10
10
|
{ name="Ali Pilehvar Meibody", email="alipilehvar1999@Gmail.com" }
|
|
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="PyGamLab",
|
|
8
|
-
version="1.2.
|
|
8
|
+
version="1.2.3",
|
|
9
9
|
author="Ali Pilehvar Meibody",
|
|
10
10
|
author_email="alipilehvar1999@gmail.com",
|
|
11
11
|
description="A scientific Python library with constants, unit convertors, formulas, and data analysis tools.",
|
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
from .gam_atom import GAM_Atom
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
from typing import Dict, Any, Optional, List, Tuple, Set, Union
|
|
8
|
-
import numpy as np
|
|
9
|
-
from dataclasses import dataclass, field
|
|
10
|
-
from enum import Enum
|
|
11
|
-
import json
|
|
12
|
-
from abc import ABC, abstractmethod
|
|
13
|
-
from scipy.spatial.distance import euclidean
|
|
14
|
-
from scipy.spatial.transform import Rotation
|
|
15
|
-
from collections import deque
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# Physical constants
|
|
19
|
-
ATOMIC_MASS_UNIT = 1.66053906660e-27 # kg
|
|
20
|
-
BOHR_RADIUS = 5.29177210903e-11 # m
|
|
21
|
-
ELEMENTARY_CHARGE = 1.602176634e-19 # C
|
|
22
|
-
|
|
23
|
-
# Bond length reference data (in Angstroms)
|
|
24
|
-
REFERENCE_BOND_LENGTHS = {
|
|
25
|
-
('C', 'C'): {'1': 1.54, '2': 1.34, '3': 1.20}, # single, double, triple
|
|
26
|
-
('C', 'H'): {'1': 1.09},
|
|
27
|
-
('C', 'O'): {'1': 1.43, '2': 1.23},
|
|
28
|
-
('C', 'N'): {'1': 1.47, '2': 1.29, '3': 1.16},
|
|
29
|
-
# Add more reference data as needed
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
REFERENCE_PERIODIC_TABLE_CONFIG={
|
|
34
|
-
'H': {'number': 1, 'mass': 1.008, 'config': '1s1', 'radius': 0.53},
|
|
35
|
-
'He': {'number': 2, 'mass': 4.003, 'config': '1s2', 'radius': 0.31},
|
|
36
|
-
'Li': {'number': 3, 'mass': 6.941, 'config': '[He] 2s1', 'radius': 1.67},
|
|
37
|
-
'Be': {'number': 4, 'mass': 9.012, 'config': '[He] 2s2', 'radius': 1.12},
|
|
38
|
-
'B': {'number': 5, 'mass': 10.811, 'config': '[He] 2s2 2p1', 'radius': 0.85},
|
|
39
|
-
'C': {'number': 6, 'mass': 12.011, 'config': '[He] 2s2 2p2', 'radius': 0.67},
|
|
40
|
-
'N': {'number': 7, 'mass': 14.007, 'config': '[He] 2s2 2p3', 'radius': 0.56},
|
|
41
|
-
'O': {'number': 8, 'mass': 15.999, 'config': '[He] 2s2 2p4', 'radius': 0.48},
|
|
42
|
-
'F': {'number': 9, 'mass': 18.998, 'config': '[He] 2s2 2p5', 'radius': 0.42},
|
|
43
|
-
'Ne': {'number': 10, 'mass': 20.180, 'config': '[He] 2s2 2p6', 'radius': 0.38},
|
|
44
|
-
'Na': {'number': 11, 'mass': 22.990, 'config': '[Ne] 3s1', 'radius': 1.90},
|
|
45
|
-
'Mg': {'number': 12, 'mass': 24.305, 'config': '[Ne] 3s2', 'radius': 1.45},
|
|
46
|
-
'Al': {'number': 13, 'mass': 26.982, 'config': '[Ne] 3s2 3p1', 'radius': 1.18},
|
|
47
|
-
'Si': {'number': 14, 'mass': 28.085, 'config': '[Ne] 3s2 3p2', 'radius': 1.11},
|
|
48
|
-
'P': {'number': 15, 'mass': 30.974, 'config': '[Ne] 3s2 3p3', 'radius': 1.06},
|
|
49
|
-
'S': {'number': 16, 'mass': 32.06, 'config': '[Ne] 3s2 3p4', 'radius': 1.02},
|
|
50
|
-
'Cl': {'number': 17, 'mass': 35.453, 'config': '[Ne] 3s2 3p5', 'radius': 0.99},
|
|
51
|
-
'Ar': {'number': 18, 'mass': 39.948, 'config': '[Ne] 3s2 3p6', 'radius': 0.95},
|
|
52
|
-
'K': {'number': 19, 'mass': 39.098, 'config': '[Ar] 4s1', 'radius': 2.43},
|
|
53
|
-
'Ca': {'number': 20, 'mass': 40.078, 'config': '[Ar] 4s2', 'radius': 1.94},
|
|
54
|
-
'Sc': {'number': 21, 'mass': 44.956, 'config': '[Ar] 3d1 4s2', 'radius': 1.84},
|
|
55
|
-
'Ti': {'number': 22, 'mass': 47.867, 'config': '[Ar] 3d2 4s2', 'radius': 1.76},
|
|
56
|
-
'V': {'number': 23, 'mass': 50.942, 'config': '[Ar] 3d3 4s2', 'radius': 1.71},
|
|
57
|
-
'Cr': {'number': 24, 'mass': 51.996, 'config': '[Ar] 3d5 4s1', 'radius': 1.66},
|
|
58
|
-
'Mn': {'number': 25, 'mass': 54.938, 'config': '[Ar] 3d5 4s2', 'radius': 1.61},
|
|
59
|
-
'Fe': {'number': 26, 'mass': 55.845, 'config': '[Ar] 3d6 4s2', 'radius': 1.56},
|
|
60
|
-
'Co': {'number': 27, 'mass': 58.933, 'config': '[Ar] 3d7 4s2', 'radius': 1.52},
|
|
61
|
-
'Ni': {'number': 28, 'mass': 58.693, 'config': '[Ar] 3d8 4s2', 'radius': 1.49},
|
|
62
|
-
'Cu': {'number': 29, 'mass': 63.546, 'config': '[Ar] 3d10 4s1', 'radius': 1.45},
|
|
63
|
-
'Zn': {'number': 30, 'mass': 65.38, 'config': '[Ar] 3d10 4s2', 'radius': 1.42},
|
|
64
|
-
'Ga': {'number': 31, 'mass': 69.723, 'config': '[Ar] 3d10 4s2 4p1', 'radius': 1.36},
|
|
65
|
-
'Ge': {'number': 32, 'mass': 72.630, 'config': '[Ar] 3d10 4s2 4p2', 'radius': 1.25},
|
|
66
|
-
'As': {'number': 33, 'mass': 74.922, 'config': '[Ar] 3d10 4s2 4p3', 'radius': 1.19},
|
|
67
|
-
'Se': {'number': 34, 'mass': 78.971, 'config': '[Ar] 3d10 4s2 4p4', 'radius': 1.16},
|
|
68
|
-
'Br': {'number': 35, 'mass': 79.904, 'config': '[Ar] 3d10 4s2 4p5', 'radius': 1.14},
|
|
69
|
-
'Kr': {'number': 36, 'mass': 83.798, 'config': '[Ar] 3d10 4s2 4p6', 'radius': 1.10}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
REFERENCE_VALENCE_ELECTRONS = {
|
|
74
|
-
# Period 1
|
|
75
|
-
'H': 1, 'He': 2,
|
|
76
|
-
# Period 2
|
|
77
|
-
'Li': 1, 'Be': 2, 'B': 3, 'C': 4, 'N': 5, 'O': 6, 'F': 7, 'Ne': 8,
|
|
78
|
-
# Period 3
|
|
79
|
-
'Na': 1, 'Mg': 2, 'Al': 3, 'Si': 4, 'P': 5, 'S': 6, 'Cl': 7, 'Ar': 8,
|
|
80
|
-
# Period 4 (main group)
|
|
81
|
-
'K': 1, 'Ca': 2, 'Ga': 3, 'Ge': 4, 'As': 5, 'Se': 6, 'Br': 7, 'Kr': 8,
|
|
82
|
-
# Period 5 (main group)
|
|
83
|
-
'Rb': 1, 'Sr': 2, 'In': 3, 'Sn': 4, 'Sb': 5, 'Te': 6, 'I': 7, 'Xe': 8,
|
|
84
|
-
# Period 6 (main group)
|
|
85
|
-
'Cs': 1, 'Ba': 2, 'Tl': 3, 'Pb': 4, 'Bi': 5, 'Po': 6, 'At': 7, 'Rn': 8,
|
|
86
|
-
# Period 7 (main group)
|
|
87
|
-
'Fr': 1, 'Ra': 2,
|
|
88
|
-
# Other common elements
|
|
89
|
-
'Sc': 3, 'Ti': 4, 'V': 5, 'Cr': 6, 'Mn': 7, 'Fe': 8, 'Co': 9, 'Ni': 10,
|
|
90
|
-
'Cu': 11, 'Zn': 12, 'Ag': 11, 'Cd': 12, 'Au': 11, 'Hg': 12
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
REFERENCE_PAULING_ELECTRONEGATIVITIES={
|
|
95
|
-
'H': 2.20, 'He': 0.00, 'Li': 0.98, 'Be': 1.57, 'B': 2.04, 'C': 2.55,
|
|
96
|
-
'N': 3.04, 'O': 3.44, 'F': 3.98, 'Ne': 0.00, 'Na': 0.93, 'Mg': 1.31,
|
|
97
|
-
'Al': 1.61, 'Si': 1.90, 'P': 2.19, 'S': 2.58, 'Cl': 3.16, 'Ar': 0.00,
|
|
98
|
-
'K': 0.82, 'Ca': 1.00, 'Sc': 1.36, 'Ti': 1.54, 'V': 1.63, 'Cr': 1.66,
|
|
99
|
-
'Mn': 1.55, 'Fe': 1.83, 'Co': 1.88, 'Ni': 1.91, 'Cu': 1.90, 'Zn': 1.65,
|
|
100
|
-
'Ga': 1.81, 'Ge': 2.01, 'As': 2.18, 'Se': 2.55, 'Br': 2.96, 'Kr': 3.00,
|
|
101
|
-
'Rb': 0.82, 'Sr': 0.95, 'Y': 1.22, 'Zr': 1.33, 'Nb': 1.60, 'Mo': 2.16,
|
|
102
|
-
'Tc': 1.90, 'Ru': 2.20, 'Rh': 2.28, 'Pd': 2.20, 'Ag': 1.93, 'Cd': 1.69,
|
|
103
|
-
'In': 1.78, 'Sn': 1.96, 'Sb': 2.05, 'Te': 2.10, 'I': 2.66, 'Xe': 2.60,
|
|
104
|
-
'Cs': 0.79, 'Ba': 0.89, 'La': 1.10, 'Hf': 1.30, 'Ta': 1.50, 'W': 2.36,
|
|
105
|
-
'Re': 1.90, 'Os': 2.20, 'Ir': 2.20, 'Pt': 2.28, 'Au': 2.54, 'Hg': 2.00,
|
|
106
|
-
'Tl': 1.62, 'Pb': 1.87, 'Bi': 2.02, 'Po': 2.00, 'At': 2.20, 'Rn': 2.20,
|
|
107
|
-
'Fr': 0.70, 'Ra': 0.90, 'Ac': 1.10, 'Th': 1.30, 'Pa': 1.50, 'U': 1.38,
|
|
108
|
-
'Np': 1.36, 'Pu': 1.28, 'Am': 1.13, 'Cm': 1.28, 'Bk': 1.30, 'Cf': 1.30,
|
|
109
|
-
'Es': 1.30, 'Fm': 1.30, 'Md': 1.30, 'No': 1.30, 'Lr': 1.30
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
class ElectronicState(Enum):
|
|
113
|
-
"""Enumeration for electronic states of atoms."""
|
|
114
|
-
GROUND_STATE = "ground"
|
|
115
|
-
EXCITED_STATE = "excited"
|
|
116
|
-
IONIZED = "ionized"
|
|
117
|
-
|
|
118
|
-
@dataclass
|
|
119
|
-
class AtomicOrbital:
|
|
120
|
-
"""Represents an atomic orbital with quantum numbers."""
|
|
121
|
-
n: int # Principal quantum number
|
|
122
|
-
l: int # Angular momentum quantum number
|
|
123
|
-
m: int # Magnetic quantum number
|
|
124
|
-
s: float # Spin quantum number
|
|
125
|
-
occupation: float = 0.0 # Electron occupation number
|
|
126
|
-
|
|
127
|
-
class AtomicData:
|
|
128
|
-
"""Static class containing fundamental atomic data."""
|
|
129
|
-
_periodic_table: Dict[str, Dict[str, Any]] =REFERENCE_PERIODIC_TABLE_CONFIG
|
|
130
|
-
|
|
131
|
-
@classmethod
|
|
132
|
-
def get_atomic_data(cls, element: str) -> Dict[str, Any]:
|
|
133
|
-
"""Get atomic data for an element."""
|
|
134
|
-
return cls._periodic_table.get(element, {})
|
|
135
|
-
|
|
136
|
-
class ForceField(ABC):
|
|
137
|
-
"""Abstract base class for force field implementations."""
|
|
138
|
-
@abstractmethod
|
|
139
|
-
def calculate_energy(self, atom: 'GAM_Atom', neighbors: List['GAM_Atom']) -> float:
|
|
140
|
-
"""Calculate the energy contribution of an atom."""
|
|
141
|
-
pass
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
class GAM_Bond:
|
|
147
|
-
"""
|
|
148
|
-
Advanced bond class for computational chemistry and molecular modeling applications.
|
|
149
|
-
|
|
150
|
-
The GAM_Bond class represents covalent bonds between atoms within molecular systems
|
|
151
|
-
and provides comprehensive functionality for structural analysis, geometric calculations,
|
|
152
|
-
and bond property evaluation. It supports various bond orders, strain energy calculations,
|
|
153
|
-
and advanced geometric transformations essential for molecular dynamics simulations
|
|
154
|
-
and quantum chemistry computations.
|
|
155
|
-
|
|
156
|
-
Attributes:
|
|
157
|
-
id (int): Unique identifier for the bond within a molecular system.
|
|
158
|
-
atom1_id (int): ID of the first atom in the bond.
|
|
159
|
-
atom2_id (int): ID of the second atom in the bond.
|
|
160
|
-
order (int): Bond order (1=single, 2=double, 3=triple).
|
|
161
|
-
_length (Optional[float]): Cached bond length in Angstroms.
|
|
162
|
-
_energy (Optional[float]): Cached bond energy in Joules.
|
|
163
|
-
|
|
164
|
-
Examples:
|
|
165
|
-
Basic bond creation:
|
|
166
|
-
>>> bond = GAM_Bond(id=1, atom1_id=1, atom2_id=2, order=1)
|
|
167
|
-
>>> print(f"Bond order: {bond.order}")
|
|
168
|
-
Bond order: 1
|
|
169
|
-
|
|
170
|
-
Bond length calculation:
|
|
171
|
-
>>> atoms = {1: GAM_Atom(1, "C", 0.0, 0.0, 0.0),
|
|
172
|
-
... 2: GAM_Atom(2, "C", 1.54, 0.0, 0.0)}
|
|
173
|
-
>>> bond = GAM_Bond(1, 1, 2, 1)
|
|
174
|
-
>>> length = bond.calculate_length(atoms)
|
|
175
|
-
>>> print(f"Bond length: {length:.2f} Å")
|
|
176
|
-
Bond length: 1.54 Å
|
|
177
|
-
|
|
178
|
-
Bond validation:
|
|
179
|
-
>>> is_reasonable = bond.is_reasonable_length(atoms)
|
|
180
|
-
>>> print(f"Reasonable bond length: {is_reasonable}")
|
|
181
|
-
Reasonable bond length: True
|
|
182
|
-
|
|
183
|
-
Strain energy calculation:
|
|
184
|
-
>>> strain_energy = bond.calculate_strain_energy(atoms)
|
|
185
|
-
>>> print(f"Strain energy: {strain_energy:.3f} kcal/mol")
|
|
186
|
-
Strain energy: 0.000 kcal/mol
|
|
187
|
-
|
|
188
|
-
Notes:
|
|
189
|
-
- Bond lengths are calculated in Angstroms.
|
|
190
|
-
- Strain energies are calculated in kcal/mol using harmonic approximation.
|
|
191
|
-
- Bond validation uses reference bond lengths with 20% tolerance.
|
|
192
|
-
- All geometric calculations require access to the complete atom dictionary.
|
|
193
|
-
|
|
194
|
-
Raises:
|
|
195
|
-
ValueError: If fixed atom ID in rotation operations is not part of the bond.
|
|
196
|
-
ValueError: If atoms associated with the bond do not exist in the provided dictionary.
|
|
197
|
-
|
|
198
|
-
See Also:
|
|
199
|
-
GAM_Atom: For individual atom representation and properties.
|
|
200
|
-
GAM_Molecule: For complete molecular system management.
|
|
201
|
-
REFERENCE_BOND_LENGTHS: For reference bond length data.
|
|
202
|
-
"""
|
|
203
|
-
|
|
204
|
-
def __init__(self, id: int, atom1_id: int, atom2_id: int, order: int = 1):
|
|
205
|
-
self.id = id
|
|
206
|
-
self.atom1_id = atom1_id
|
|
207
|
-
self.atom2_id = atom2_id
|
|
208
|
-
self.order = order
|
|
209
|
-
self._length: Optional[float] = None
|
|
210
|
-
self._energy: Optional[float] = None
|
|
211
|
-
|
|
212
|
-
@property
|
|
213
|
-
def bond_vector(self, atoms: Dict[int, GAM_Atom]) -> np.ndarray:
|
|
214
|
-
"""Calculate the bond vector from atom1 to atom2."""
|
|
215
|
-
atom1 = atoms[self.atom1_id]
|
|
216
|
-
atom2 = atoms[self.atom2_id]
|
|
217
|
-
return atom2.position - atom1.position
|
|
218
|
-
|
|
219
|
-
def calculate_length(self, atoms: Dict[int, GAM_Atom]) -> float:
|
|
220
|
-
"""Calculate the bond length in Angstroms."""
|
|
221
|
-
return np.linalg.norm(self.bond_vector(atoms))
|
|
222
|
-
|
|
223
|
-
def is_reasonable_length(self, atoms: Dict[int, GAM_Atom]) -> bool:
|
|
224
|
-
"""
|
|
225
|
-
Check if the bond length is reasonable based on reference data.
|
|
226
|
-
|
|
227
|
-
Args:
|
|
228
|
-
atoms: Dictionary mapping atom IDs to Atom objects
|
|
229
|
-
|
|
230
|
-
Returns:
|
|
231
|
-
bool: True if the bond length is within 20% of reference value
|
|
232
|
-
"""
|
|
233
|
-
atom1 = atoms[self.atom1_id]
|
|
234
|
-
atom2 = atoms[self.atom2_id]
|
|
235
|
-
|
|
236
|
-
# Sort elements to match reference data format
|
|
237
|
-
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
238
|
-
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
239
|
-
ref_length = ref_lengths.get(str(self.order))
|
|
240
|
-
|
|
241
|
-
if ref_length is None:
|
|
242
|
-
return True # No reference data available
|
|
243
|
-
|
|
244
|
-
actual_length = self.calculate_length(atoms)
|
|
245
|
-
return abs(actual_length - ref_length) / ref_length < 0.2
|
|
246
|
-
|
|
247
|
-
#maybe mroe reliable:
|
|
248
|
-
def is_reasonable_length(self, atoms: Dict[int, GAM_Atom]) -> bool:
|
|
249
|
-
"""
|
|
250
|
-
Check if the bond length is reasonable based on reference data.
|
|
251
|
-
...
|
|
252
|
-
"""
|
|
253
|
-
atom1 = atoms[self.atom1_id]
|
|
254
|
-
atom2 = atoms[self.atom2_id]
|
|
255
|
-
|
|
256
|
-
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
257
|
-
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
258
|
-
# Corrected lookup to use integer key
|
|
259
|
-
ref_length = ref_lengths.get(self.order)
|
|
260
|
-
|
|
261
|
-
if ref_length is None:
|
|
262
|
-
return True
|
|
263
|
-
|
|
264
|
-
actual_length = self.calculate_length(atoms)
|
|
265
|
-
return abs(actual_length - ref_length) / ref_length < 0.2
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
def calculate_angle_with(self, other: 'GAM_Bond', atoms: Dict[int, GAM_Atom]) -> float:
|
|
271
|
-
"""
|
|
272
|
-
Calculate angle between this bond and another bond.
|
|
273
|
-
|
|
274
|
-
Args:
|
|
275
|
-
other: Another Bond object
|
|
276
|
-
atoms: Dictionary mapping atom IDs to Atom objects
|
|
277
|
-
|
|
278
|
-
Returns:
|
|
279
|
-
float: Angle in degrees between the bonds
|
|
280
|
-
"""
|
|
281
|
-
v1 = self.bond_vector(atoms)
|
|
282
|
-
v2 = other.bond_vector(atoms)
|
|
283
|
-
cos_angle = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
|
|
284
|
-
return np.degrees(np.arccos(np.clip(cos_angle, -1.0, 1.0)))
|
|
285
|
-
|
|
286
|
-
def rotate_around_axis(self,
|
|
287
|
-
axis: np.ndarray,
|
|
288
|
-
angle_degrees: float,
|
|
289
|
-
atoms: Dict[int, GAM_Atom],
|
|
290
|
-
fixed_atom_id: Optional[int] = None) -> None:
|
|
291
|
-
"""
|
|
292
|
-
Rotate the bond around an axis while keeping one atom fixed.
|
|
293
|
-
|
|
294
|
-
Args:
|
|
295
|
-
axis: Rotation axis
|
|
296
|
-
angle_degrees: Rotation angle in degrees
|
|
297
|
-
atoms: Dictionary mapping atom IDs to Atom objects
|
|
298
|
-
fixed_atom_id: ID of the atom to keep fixed (defaults to atom1_id)
|
|
299
|
-
"""
|
|
300
|
-
if fixed_atom_id is None:
|
|
301
|
-
fixed_atom_id = self.atom1_id
|
|
302
|
-
|
|
303
|
-
if fixed_atom_id not in {self.atom1_id, self.atom2_id}:
|
|
304
|
-
raise ValueError(f"Fixed atom ID must be either {self.atom1_id} or {self.atom2_id}.")
|
|
305
|
-
|
|
306
|
-
moving_atom_id = self.atom2_id if fixed_atom_id == self.atom1_id else self.atom1_id
|
|
307
|
-
|
|
308
|
-
# Get the fixed atom's position as rotation center
|
|
309
|
-
center = atoms[fixed_atom_id].position
|
|
310
|
-
|
|
311
|
-
# Rotate the moving atom
|
|
312
|
-
atoms[moving_atom_id].rotate_around_axis(axis, angle_degrees, center)
|
|
313
|
-
|
|
314
|
-
def calculate_strain_energy(self, atoms: Dict[int, GAM_Atom]) -> float:
|
|
315
|
-
"""
|
|
316
|
-
Calculate the strain energy of the bond based on deviation from ideal length.
|
|
317
|
-
|
|
318
|
-
Args:
|
|
319
|
-
atoms: Dictionary mapping atom IDs to Atom objects
|
|
320
|
-
|
|
321
|
-
Returns:
|
|
322
|
-
float: Strain energy in kcal/mol
|
|
323
|
-
"""
|
|
324
|
-
atom1 = atoms[self.atom1_id]
|
|
325
|
-
atom2 = atoms[self.atom2_id]
|
|
326
|
-
|
|
327
|
-
elements = tuple(sorted([atom1.element, atom2.element]))
|
|
328
|
-
ref_lengths = REFERENCE_BOND_LENGTHS.get(elements, {})
|
|
329
|
-
ref_length = ref_lengths.get(str(self.order))
|
|
330
|
-
|
|
331
|
-
if ref_length is None:
|
|
332
|
-
return 0.0
|
|
333
|
-
|
|
334
|
-
actual_length = self.calculate_length(atoms)
|
|
335
|
-
# Simple harmonic approximation
|
|
336
|
-
force_constant = 100.0 # kcal/mol/Ų (approximate)
|
|
337
|
-
return 0.5 * force_constant * (actual_length - ref_length) ** 2
|
|
338
|
-
|
|
339
|
-
def get_elements(self, atoms: Dict[int, 'GAM_Atom']) -> Tuple[str, str]:
|
|
340
|
-
"""
|
|
341
|
-
Returns a tuple of the elements involved in the bond.
|
|
342
|
-
|
|
343
|
-
Args:
|
|
344
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
345
|
-
|
|
346
|
-
Returns:
|
|
347
|
-
A sorted tuple of the elements (e.g., ('C', 'H')).
|
|
348
|
-
"""
|
|
349
|
-
atom1 = atoms[self.atom1_id]
|
|
350
|
-
atom2 = atoms[self.atom2_id]
|
|
351
|
-
return tuple(sorted([atom1.element, atom2.element]))
|
|
352
|
-
|
|
353
|
-
def get_bond_type(self, atoms: Dict[int, 'GAM_Atom']) -> str:
|
|
354
|
-
"""
|
|
355
|
-
Returns a descriptive string for the bond type.
|
|
356
|
-
|
|
357
|
-
Args:
|
|
358
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
359
|
-
|
|
360
|
-
Returns:
|
|
361
|
-
A string describing the bond (e.g., 'C-C single bond').
|
|
362
|
-
"""
|
|
363
|
-
elements = self.get_elements(atoms)
|
|
364
|
-
bond_order_map = {1: 'single', 2: 'double', 3: 'triple'}
|
|
365
|
-
bond_type = bond_order_map.get(self.order, 'unspecified')
|
|
366
|
-
return f"{elements[0]}-{elements[1]} {bond_type} bond"
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
def is_aromatic(self, atoms: Dict[int, 'GAM_Atom']) -> bool:
|
|
371
|
-
"""
|
|
372
|
-
Checks if the bond is likely part of an aromatic system.
|
|
373
|
-
This is a simple heuristic based on bond order and element types.
|
|
374
|
-
|
|
375
|
-
Args:
|
|
376
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
377
|
-
|
|
378
|
-
Returns:
|
|
379
|
-
True if the bond is aromatic, False otherwise.
|
|
380
|
-
"""
|
|
381
|
-
if self.order == 1:
|
|
382
|
-
elements = self.get_elements(atoms)
|
|
383
|
-
# Aromatic bonds are often C-C bonds with an order of 1.5,
|
|
384
|
-
# but in some representations, they are labeled as order 1.
|
|
385
|
-
if elements == ('C', 'C'):
|
|
386
|
-
# Check for a more subtle indicator of aromaticity, such as sp2 hybridization
|
|
387
|
-
atom1 = atoms[self.atom1_id]
|
|
388
|
-
atom2 = atoms[self.atom2_id]
|
|
389
|
-
# A common heuristic is checking if both atoms have 3 neighbors
|
|
390
|
-
if len(atom1._bonds) == 3 and len(atom2._bonds) == 3:
|
|
391
|
-
return True
|
|
392
|
-
return False
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
def calculate_dihedral_angle(self, atom3_id: int, atom4_id: int, atoms: Dict[int, 'GAM_Atom']) -> float:
|
|
396
|
-
"""
|
|
397
|
-
Calculates the dihedral angle between this bond and a plane defined by
|
|
398
|
-
the third and fourth atoms.
|
|
399
|
-
|
|
400
|
-
Args:
|
|
401
|
-
atom3_id: The ID of the third atom.
|
|
402
|
-
atom4_id: The ID of the fourth atom.
|
|
403
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
404
|
-
|
|
405
|
-
Returns:
|
|
406
|
-
The dihedral angle in degrees.
|
|
407
|
-
"""
|
|
408
|
-
atom1 = atoms[self.atom1_id]
|
|
409
|
-
atom2 = atoms[self.atom2_id]
|
|
410
|
-
atom3 = atoms[atom3_id]
|
|
411
|
-
atom4 = atoms[atom4_id]
|
|
412
|
-
|
|
413
|
-
b1 = atom1.position - atom2.position
|
|
414
|
-
b2 = atom3.position - atom2.position
|
|
415
|
-
b3 = atom4.position - atom3.position
|
|
416
|
-
|
|
417
|
-
n1 = np.cross(b1, b2)
|
|
418
|
-
n2 = np.cross(b2, b3)
|
|
419
|
-
|
|
420
|
-
m1 = np.cross(n1, b2 / np.linalg.norm(b2))
|
|
421
|
-
|
|
422
|
-
x = np.dot(n1, n2)
|
|
423
|
-
y = np.dot(m1, n2)
|
|
424
|
-
|
|
425
|
-
return np.degrees(np.arctan2(y, x))
|
|
426
|
-
|
|
427
|
-
def calculate_angle_with_plane(self, plane_normal: np.ndarray, atoms: Dict[int, 'GAM_Atom']) -> float:
|
|
428
|
-
"""
|
|
429
|
-
Calculates the angle between the bond vector and a user-defined plane.
|
|
430
|
-
|
|
431
|
-
Args:
|
|
432
|
-
plane_normal: The normal vector of the plane.
|
|
433
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
434
|
-
|
|
435
|
-
Returns:
|
|
436
|
-
The angle in degrees.
|
|
437
|
-
"""
|
|
438
|
-
bond_vector = self.bond_vector(atoms)
|
|
439
|
-
normal_vec = plane_normal / np.linalg.norm(plane_normal)
|
|
440
|
-
|
|
441
|
-
# The angle between the vector and the normal of the plane
|
|
442
|
-
cos_angle_to_normal = np.dot(bond_vector, normal_vec) / (np.linalg.norm(bond_vector))
|
|
443
|
-
|
|
444
|
-
# The angle with the plane is 90 degrees minus the angle with the normal
|
|
445
|
-
angle_with_plane_rad = np.pi / 2 - np.arccos(np.clip(cos_angle_to_normal, -1.0, 1.0))
|
|
446
|
-
|
|
447
|
-
return np.degrees(angle_with_plane_rad)
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
def to_dict(self) -> Dict[str, Any]:
|
|
452
|
-
"""
|
|
453
|
-
Serializes the bond's data into a dictionary.
|
|
454
|
-
|
|
455
|
-
Returns:
|
|
456
|
-
A dictionary representation of the bond.
|
|
457
|
-
"""
|
|
458
|
-
return {
|
|
459
|
-
'id': self.id,
|
|
460
|
-
'atom1_id': self.atom1_id,
|
|
461
|
-
'atom2_id': self.atom2_id,
|
|
462
|
-
'order': self.order
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
def get_atoms(self, atoms: Dict[int, 'GAM_Atom']) -> Tuple['GAM_Atom', 'GAM_Atom']:
|
|
466
|
-
"""
|
|
467
|
-
Retrieves the two GAM_Atom objects connected by this bond.
|
|
468
|
-
|
|
469
|
-
Args:
|
|
470
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
471
|
-
|
|
472
|
-
Returns:
|
|
473
|
-
A tuple containing the two GAM_Atom objects.
|
|
474
|
-
"""
|
|
475
|
-
atom1 = atoms.get(self.atom1_id)
|
|
476
|
-
atom2 = atoms.get(self.atom2_id)
|
|
477
|
-
if not all([atom1, atom2]):
|
|
478
|
-
raise ValueError("One or more atoms associated with this bond do not exist.")
|
|
479
|
-
return atom1, atom2
|
|
480
|
-
|
|
481
|
-
def get_neighboring_bonds(self, atoms: Dict[int, 'GAM_Atom']) -> List['GAM_Bond']:
|
|
482
|
-
"""
|
|
483
|
-
Finds all other bonds that share an atom with this bond.
|
|
484
|
-
|
|
485
|
-
Args:
|
|
486
|
-
atoms: Dictionary mapping atom IDs to Atom objects.
|
|
487
|
-
|
|
488
|
-
Returns:
|
|
489
|
-
A list of GAM_Bond objects that are neighbors to this bond.
|
|
490
|
-
"""
|
|
491
|
-
atom1, atom2 = self.get_atoms(atoms)
|
|
492
|
-
neighboring_bonds = []
|
|
493
|
-
for bond in atom1.get_bonds():
|
|
494
|
-
if bond.id != self.id:
|
|
495
|
-
neighboring_bonds.append(bond)
|
|
496
|
-
for bond in atom2.get_bonds():
|
|
497
|
-
if bond.id != self.id and bond not in neighboring_bonds:
|
|
498
|
-
neighboring_bonds.append(bond)
|
|
499
|
-
return neighboring_bonds
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
def is_part_of_ring(self, atoms: Dict[int, 'GAM_Atom'], max_ring_size: int = 7) -> bool:
|
|
504
|
-
"""
|
|
505
|
-
Checks if the bond is part of a closed ring structure using Breadth-First Search (BFS).
|
|
506
|
-
...
|
|
507
|
-
"""
|
|
508
|
-
atom1, atom2 = self.get_atoms(atoms)
|
|
509
|
-
|
|
510
|
-
# Use a more efficient deque for the queue
|
|
511
|
-
queue = deque([(atom2, 1, {atom2.id})]) # (current_atom, path_length, visited_set)
|
|
512
|
-
|
|
513
|
-
while queue:
|
|
514
|
-
current_atom, path_length, visited = queue.popleft()
|
|
515
|
-
|
|
516
|
-
if path_length >= max_ring_size:
|
|
517
|
-
continue
|
|
518
|
-
|
|
519
|
-
for bond in current_atom.get_bonds():
|
|
520
|
-
if bond.id == self.id:
|
|
521
|
-
continue
|
|
522
|
-
|
|
523
|
-
neighbor = atoms[bond.atom2_id if bond.atom1_id == current_atom.id else bond.atom1_id]
|
|
524
|
-
|
|
525
|
-
if neighbor.id == atom1.id:
|
|
526
|
-
return True # Found a path back to atom1, forming a ring
|
|
527
|
-
|
|
528
|
-
if neighbor.id not in visited:
|
|
529
|
-
new_visited = visited.copy()
|
|
530
|
-
new_visited.add(neighbor.id)
|
|
531
|
-
queue.append((neighbor, path_length + 1, new_visited))
|
|
532
|
-
return False
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
@classmethod
|
|
537
|
-
def from_dict(cls, data: Dict[str, Any]) -> 'GAM_Bond':
|
|
538
|
-
"""
|
|
539
|
-
Reconstructs a GAM_Bond object from a dictionary.
|
|
540
|
-
|
|
541
|
-
Args:
|
|
542
|
-
data: A dictionary containing the bond's data.
|
|
543
|
-
|
|
544
|
-
Returns:
|
|
545
|
-
A new GAM_Bond object.
|
|
546
|
-
"""
|
|
547
|
-
return cls(
|
|
548
|
-
id=data['id'],
|
|
549
|
-
atom1_id=data['atom1_id'],
|
|
550
|
-
atom2_id=data['atom2_id'],
|
|
551
|
-
order=data['order']
|
|
552
|
-
)
|
|
553
|
-
|
|
554
|
-
def to_json(self, filepath: str):
|
|
555
|
-
"""
|
|
556
|
-
Saves the bond's data to a JSON file.
|
|
557
|
-
|
|
558
|
-
Args:
|
|
559
|
-
filepath: The path to the output JSON file.
|
|
560
|
-
"""
|
|
561
|
-
with open(filepath, 'w') as f:
|
|
562
|
-
json.dump(self.to_dict(), f, indent=4)
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
def __repr__(self) -> str:
|
|
567
|
-
return f"Bond(id={self.id}, atom1_id={self.atom1_id}, atom2_id={self.atom2_id}, order={self.order})"
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pygamlab-1.2.2 → pygamlab-1.2.3}/PyGamLab/structures/GAM_architectures/GAM_nano_particles.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|