@@ -604,7 +604,7 @@ def test_add_by_list(self, h2o):
604
604
temp_comp .add (comp_list , label = label_list )
605
605
a = [k for k , v in temp_comp .labels .items ()]
606
606
assert a == [
607
- "water " ,
607
+ "all-waters " ,
608
608
"water[0]" ,
609
609
"water[1]" ,
610
610
"water[2]" ,
@@ -783,42 +783,14 @@ def test_remove(self, ethane):
783
783
784
784
# Test to reset labels after hydrogens
785
785
ethane6 = mb .clone (ethane )
786
- ethane6 .flatten ()
787
786
hydrogens = ethane6 .particles_by_name ("H" )
788
- ethane6 .remove (hydrogens )
787
+ ethane6 .remove (hydrogens , reset_labels = True )
789
788
assert list (ethane6 .labels .keys ()) == [
790
789
"methyl1" ,
791
790
"methyl2" ,
792
- "C" ,
793
- "C[0]" ,
794
- "H" ,
795
- "C[1]" ,
796
- "port" ,
797
- "port[1]" ,
798
- "port[3]" ,
799
- "port[5]" ,
800
- "port[7]" ,
801
- "port[9]" ,
802
- "port[11]" ,
803
- ]
804
-
805
- ethane7 = mb .clone (ethane )
806
- ethane7 .flatten ()
807
- hydrogens = ethane7 .particles_by_name ("H" )
808
- ethane7 .remove (hydrogens , reset_labels = True )
809
-
810
- assert list (ethane7 .labels .keys ()) == [
811
- "C" ,
812
- "C[0]" ,
813
- "C[1]" ,
814
- "port" ,
815
- "port[0]" ,
816
- "port[1]" ,
817
- "port[2]" ,
818
- "port[3]" ,
819
- "port[4]" ,
820
- "port[5]" ,
821
791
]
792
+ assert ethane6 .available_ports () == []
793
+ assert len (ethane6 .all_ports ()) == 6
822
794
823
795
def test_remove_many (self , ethane ):
824
796
ethane .remove ([ethane .children [0 ], ethane .children [1 ]])
@@ -1041,6 +1013,31 @@ def test_flatten_box_of_eth(self, ethane):
1041
1013
box_of_eth .flatten ()
1042
1014
assert len (box_of_eth .children ) == box_of_eth .n_particles == 8 * 2
1043
1015
assert box_of_eth .n_bonds == 7 * 2
1016
+ assert list (box_of_eth .labels .keys ()) == [
1017
+ "all-Cs" ,
1018
+ "C[0]" ,
1019
+ "all-Hs" ,
1020
+ "H[0]" ,
1021
+ "H[1]" ,
1022
+ "H[2]" ,
1023
+ "C[1]" ,
1024
+ "H[3]" ,
1025
+ "H[4]" ,
1026
+ "H[5]" ,
1027
+ "C[2]" ,
1028
+ "H[6]" ,
1029
+ "H[7]" ,
1030
+ "H[8]" ,
1031
+ "C[3]" ,
1032
+ "H[9]" ,
1033
+ "H[10]" ,
1034
+ "H[11]" ,
1035
+ ]
1036
+
1037
+ def test_flatten_then_fill_box (self , benzene ):
1038
+ benzene .flatten (inplace = True )
1039
+ benzene_box = mb .packing .fill_box (compound = benzene , n_compounds = 2 , density = 0.3 )
1040
+ assert next (iter (benzene_box .particles ())).root .bond_graph
1044
1041
1045
1042
def test_flatten_with_port (self , ethane ):
1046
1043
ethane .remove (ethane [2 ])
@@ -1726,7 +1723,7 @@ def test_energy_minimize_shift_com(self, octane):
1726
1723
"win" in sys .platform , reason = "Unknown issue with Window's Open Babel "
1727
1724
)
1728
1725
def test_energy_minimize_shift_anchor (self , octane ):
1729
- anchor_compound = octane .labels ["chain" ].labels ["CH3" ][ 0 ]
1726
+ anchor_compound = octane .labels ["chain" ].labels ["CH3[0]" ]
1730
1727
pos_old = anchor_compound .pos
1731
1728
octane .energy_minimize (anchor = anchor_compound )
1732
1729
# check to see if COM of the anchor Compound
@@ -1738,9 +1735,9 @@ def test_energy_minimize_shift_anchor(self, octane):
1738
1735
"win" in sys .platform , reason = "Unknown issue with Window's Open Babel "
1739
1736
)
1740
1737
def test_energy_minimize_fix_compounds (self , octane ):
1741
- methyl_end0 = octane .labels ["chain" ].labels ["CH3" ][ 0 ]
1742
- methyl_end1 = octane .labels ["chain" ].labels ["CH3" ][ 1 ]
1743
- carbon_end = octane .labels ["chain" ].labels ["CH3" ] [0 ].labels ["C" ][ 0 ]
1738
+ methyl_end0 = octane .labels ["chain" ].labels ["CH3[0]" ]
1739
+ methyl_end1 = octane .labels ["chain" ].labels ["CH3[0]" ]
1740
+ carbon_end = octane .labels ["chain" ].labels ["CH3[0]" ] .labels ["C[0]" ]
1744
1741
not_in_compound = mb .Compound (name = "H" )
1745
1742
1746
1743
# fix the whole molecule and make sure positions are close
@@ -1827,9 +1824,9 @@ def test_energy_minimize_fix_compounds(self, octane):
1827
1824
"win" in sys .platform , reason = "Unknown issue with Window's Open Babel "
1828
1825
)
1829
1826
def test_energy_minimize_ignore_compounds (self , octane ):
1830
- methyl_end0 = octane .labels ["chain" ].labels ["CH3" ][ 0 ]
1831
- methyl_end1 = octane .labels ["chain" ].labels ["CH3" ][ 1 ]
1832
- carbon_end = octane .labels ["chain" ].labels ["CH3" ] [0 ].labels ["C" ][ 0 ]
1827
+ methyl_end0 = octane .labels ["chain" ].labels ["CH3[0]" ]
1828
+ methyl_end1 = octane .labels ["chain" ].labels ["CH3[1]" ]
1829
+ carbon_end = octane .labels ["chain" ].labels ["CH3[0]" ] .labels ["C[0]" ]
1833
1830
not_in_compound = mb .Compound (name = "H" )
1834
1831
1835
1832
# fix the whole molecule and make sure positions are close
@@ -1859,12 +1856,12 @@ def test_energy_minimize_ignore_compounds(self, octane):
1859
1856
"win" in sys .platform , reason = "Unknown issue with Window's Open Babel "
1860
1857
)
1861
1858
def test_energy_minimize_distance_constraints (self , octane ):
1862
- methyl_end0 = octane .labels ["chain" ].labels ["CH3" ][ 0 ]
1863
- methyl_end1 = octane .labels ["chain" ].labels ["CH3" ][ 1 ]
1859
+ methyl_end0 = octane .labels ["chain" ].labels ["CH3[0]" ]
1860
+ methyl_end1 = octane .labels ["chain" ].labels ["CH3[1]" ]
1864
1861
1865
- carbon_end0 = octane .labels ["chain" ].labels ["CH3" ] [0 ].labels ["C" ][ 0 ]
1866
- carbon_end1 = octane .labels ["chain" ].labels ["CH3" ] [1 ].labels ["C" ][ 0 ]
1867
- h_end0 = octane .labels ["chain" ].labels ["CH3" ] [0 ].labels ["H" ][ 0 ]
1862
+ carbon_end0 = octane .labels ["chain" ].labels ["CH3[0]" ] .labels ["C[0]" ]
1863
+ carbon_end1 = octane .labels ["chain" ].labels ["CH3[1]" ] .labels ["C[0]" ]
1864
+ h_end0 = octane .labels ["chain" ].labels ["CH3[0]" ] .labels ["H[0]" ]
1868
1865
1869
1866
not_in_compound = mb .Compound (name = "H" )
1870
1867
@@ -2539,3 +2536,10 @@ def test_catalog_bondgraph_types(self, benzene):
2539
2536
catalog_bondgraph_type (compound .children [1 ][0 ], compound .bond_graph )
2540
2537
== "particle_graph"
2541
2538
)
2539
+
2540
+ def test_reset_labels (self ):
2541
+ ethane = mb .load ("CC" , smiles = True )
2542
+ Hs = ethane .particles_by_name ("H" )
2543
+ ethane .remove (Hs , reset_labels = True )
2544
+ ports = set (f"port[{ i } ]" for i in range (6 ))
2545
+ assert ports .issubset (set (ethane .labels .keys ()))
0 commit comments