File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,15 @@ def get_axis_grid(self, ind):
129
129
def __add__ (self , other ):
130
130
return self .linear_add (other , 1.0 )
131
131
132
+ def __radd__ (self , other ):
133
+ if other == 0 or other is None :
134
+ # sum() calls 0 + self first; we treat 0 as the identity element
135
+ return self
136
+ if isinstance (other , self .__class__ ):
137
+ return self .__add__ (other )
138
+
139
+ raise TypeError (f"Unsupported operand type(s) for +: '{ type (other ).__name__ } ' and '{ type (self ).__name__ } '" )
140
+
132
141
def __sub__ (self , other ):
133
142
return self .linear_add (other , - 1.0 )
134
143
Original file line number Diff line number Diff line change @@ -1585,6 +1585,9 @@ def test_init(self):
1585
1585
chgcar = self .chgcar_spin + self .chgcar_spin
1586
1586
assert chgcar .get_integrated_diff (0 , 1 )[0 , 1 ] == approx (- 0.0043896932237534022 * 2 )
1587
1587
1588
+ chgcar = sum ([self .chgcar_spin , self .chgcar_spin ])
1589
+ assert chgcar .get_integrated_diff (0 , 1 )[0 , 1 ] == approx (- 0.0043896932237534022 * 2 )
1590
+
1588
1591
chgcar = self .chgcar_spin - self .chgcar_spin
1589
1592
assert chgcar .get_integrated_diff (0 , 1 )[0 , 1 ] == approx (0 )
1590
1593
You can’t perform that action at this time.
0 commit comments