HTPolyNet 2.17.1__py3-none-any.whl → 2.18.1__py3-none-any.whl
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.
- htpolynet/analysis/plot.py +115 -13
- htpolynet/analysis/utils.py +30 -0
- htpolynet/core/configuration.py +6 -1
- htpolynet/core/molecule.py +8 -1
- htpolynet/core/topology.py +37 -3
- htpolynet/cure/curecontroller.py +17 -1
- htpolynet/cure/ringcontroller.py +13 -1
- htpolynet/external/smiles_input.py +266 -8
- htpolynet/io/mol2.py +4 -1
- htpolynet/resources/claude/SKILL.md +26 -7
- htpolynet/resources/example_depot/0-liquid-styrene.yaml +5 -4
- htpolynet/resources/example_depot/1-polystyrene.yaml +10 -26
- htpolynet/resources/example_depot/2-bisgma-styrene-thermoset.yaml +17 -46
- htpolynet/resources/example_depot/3-pacm-dgeba-epoxy-thermoset.yaml +9 -26
- htpolynet/resources/example_depot/4-dfda-fde-epoxy-thermoset.yaml +9 -25
- htpolynet/resources/example_depot/5-htpb-ipdi.yaml +17 -13
- htpolynet/resources/example_depot/6-cyanate-ester.yaml +8 -2
- htpolynet/schema/base.yaml +41 -0
- {htpolynet-2.17.1.dist-info → htpolynet-2.18.1.dist-info}/METADATA +1 -1
- {htpolynet-2.17.1.dist-info → htpolynet-2.18.1.dist-info}/RECORD +23 -23
- {htpolynet-2.17.1.dist-info → htpolynet-2.18.1.dist-info}/WHEEL +0 -0
- {htpolynet-2.17.1.dist-info → htpolynet-2.18.1.dist-info}/entry_points.txt +0 -0
- {htpolynet-2.17.1.dist-info → htpolynet-2.18.1.dist-info}/licenses/LICENSE +0 -0
htpolynet/analysis/plot.py
CHANGED
|
@@ -667,6 +667,15 @@ def build_plots(args):
|
|
|
667
667
|
# dist_bw_xlinks_plot(am,os.path.join(p,"dist_bw_xlinks.png"))
|
|
668
668
|
|
|
669
669
|
def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[10,20]):
|
|
670
|
+
"""Tg from each ladder's density curve, by the two-line crossing.
|
|
671
|
+
|
|
672
|
+
The reported Tg is the two-line crossing (:func:`compute_tg`) of the curve averaged
|
|
673
|
+
over builds, with the crossing of each build's own curve giving the between-build
|
|
674
|
+
spread. The whole-curve hyperbola fit (:func:`pooled_tg`) is still computed and
|
|
675
|
+
logged, but only as a diagnostic: its Tg depends on whether density, ln density or
|
|
676
|
+
specific volume is fitted, and drifts with the ladder's top (Cameron, 2026-11-16:
|
|
677
|
+
"for Tg, crossing, not hyperbole").
|
|
678
|
+
"""
|
|
670
679
|
res={}
|
|
671
680
|
means={}
|
|
672
681
|
stds={}
|
|
@@ -675,13 +684,27 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
675
684
|
spread=[]
|
|
676
685
|
span=[]
|
|
677
686
|
whole=[]
|
|
678
|
-
|
|
687
|
+
per_build=[]
|
|
679
688
|
for i,phase in enumerate(phases):
|
|
680
689
|
p=phase['ladder']
|
|
690
|
+
# a ladder that crashed leaves no ladder.csv; it must not take the finished
|
|
691
|
+
# ladders down with it (htpolynet-sweep lost two complete example-3 cooling
|
|
692
|
+
# ladders that way when their heating partners died, job 26725677)
|
|
693
|
+
found=[]
|
|
694
|
+
for d in projdirs:
|
|
695
|
+
f=os.path.join(d,p['subdir'],'ladder.csv')
|
|
696
|
+
if os.path.exists(f):
|
|
697
|
+
found.append(f)
|
|
698
|
+
else:
|
|
699
|
+
logger.warning(f'{f} not found (did this ladder finish?); leaving {d} out of '
|
|
700
|
+
f'ladder {i} ({p["subdir"]})')
|
|
701
|
+
if not found:
|
|
702
|
+
logger.warning(f'no build has ladder {i} ({p["subdir"]}); skipping it')
|
|
703
|
+
continue
|
|
681
704
|
rate.append(p['deltaT']/(p['ps_per_rise']+p['ps_per_run']))
|
|
682
705
|
res[i]=[]
|
|
683
|
-
for
|
|
684
|
-
df=pd.read_csv(
|
|
706
|
+
for f in found:
|
|
707
|
+
df=pd.read_csv(f,index_col=None,header=0)
|
|
685
708
|
t0=p['warmup_ps']
|
|
686
709
|
ps_per_step=p['ps_per_rise']+p['ps_per_run']
|
|
687
710
|
final_ps=df['time(ps)'].iloc[-1]
|
|
@@ -706,13 +729,20 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
706
729
|
|
|
707
730
|
res[i].append(pd.DataFrame({'Temperature':T,'Volume':V,'Density':rho,'Temperature-std':Tstd,'Volume-std':Vstd,'Density-std':rhostd}))
|
|
708
731
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
732
|
+
# mean and spread over builds at each rung. Side-by-side concat and stack(), as
|
|
733
|
+
# this used to do, is refused by pandas >= 3 whenever there is more than one build
|
|
734
|
+
# (duplicate column names); do_E_plots had the same break.
|
|
735
|
+
df_concat0=pd.concat(res[i],keys=range(len(res[i])))
|
|
736
|
+
means[i]=df_concat0.groupby(level=1).mean().sort_index(axis=1)
|
|
737
|
+
stds[i]=df_concat0.groupby(level=1).std().sort_index(axis=1)
|
|
712
738
|
means[i]['Volume-std']=stds[i]['Volume']
|
|
713
739
|
means[i]['Density-std']=stds[i]['Density']
|
|
714
740
|
|
|
715
741
|
|
|
742
|
+
if not means:
|
|
743
|
+
logger.warning('no ladder finished in any build; no Tg to report')
|
|
744
|
+
return {'heating':None,'cooling':None,'directions':[],'window_range':[],
|
|
745
|
+
'unquotable':[],'whole_curve':[]}
|
|
716
746
|
fig,ax=plt.subplots(1,max(2,len(means)),figsize=(10,6),sharex=True,sharey=True)
|
|
717
747
|
for i,v in enumerate(means.keys()):
|
|
718
748
|
m=means[v]
|
|
@@ -723,7 +753,7 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
723
753
|
ax[i].set_xlabel('Temperature [K]')
|
|
724
754
|
ax[i].set_title('heating' if rate[i]>0 else 'cooling')
|
|
725
755
|
ax[i].set_ylabel('Density [kg/m$^3$]')
|
|
726
|
-
if
|
|
756
|
+
if len(res[v])<2:
|
|
727
757
|
ax[i].scatter(m['Temperature'],m['Density'])
|
|
728
758
|
else:
|
|
729
759
|
ax[i].errorbar(m['Temperature'],m['Density'],std['Density'])
|
|
@@ -731,9 +761,14 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
731
761
|
Tgs.append(Tg)
|
|
732
762
|
spread.append(tg_window_range(m['Temperature'].values,m['Density'].values))
|
|
733
763
|
curves=[(r['Temperature'].values,r['Density'].values) for r in res[v]]
|
|
764
|
+
per_build.append(_crossing_per_build(curves,n_points))
|
|
734
765
|
w=pooled_tg(curves)
|
|
735
766
|
if len(curves)==1 and w['fit'] is not None and not w['fit']['held_out']:
|
|
736
767
|
w['fit']=fit_tg_hyperbola(*curves[0],n_synth=200)
|
|
768
|
+
f=w['fit']
|
|
769
|
+
w['ceiling_drift']=(ceiling_drift(curves) if f is not None and not f['held_out']
|
|
770
|
+
else None)
|
|
771
|
+
w['rung']=float(np.median(np.abs(np.diff(curves[0][0]))))
|
|
737
772
|
whole.append(w)
|
|
738
773
|
span.append((m['Temperature'].min(),m['Temperature'].max()))
|
|
739
774
|
if Tg!=-1:
|
|
@@ -752,8 +787,12 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
752
787
|
# plan B on example 5, 2026-10-23)
|
|
753
788
|
labels=['heating' if r>0 else 'cooling' for r in rate]
|
|
754
789
|
logger.info(f'{outfile} created.')
|
|
755
|
-
for label,Tg,r in zip(labels,Tgs,rate):
|
|
756
|
-
logger.info(f'{label} Tg = {Tg:.2f} K ({(Tg-273.15):.2f} C) at {r:.5f} K/ps ({r*1.e12:.3e} K/s)'
|
|
790
|
+
for label,Tg,r,b in zip(labels,Tgs,rate,per_build):
|
|
791
|
+
logger.info(f'{label} Tg = {Tg:.2f} K ({(Tg-273.15):.2f} C) at {r:.5f} K/ps ({r*1.e12:.3e} K/s), '
|
|
792
|
+
f'two-line crossing of the mean curve')
|
|
793
|
+
if b['sd'] is not None:
|
|
794
|
+
logger.info(f'{label} Tg, two-line crossing per build: {b["mean"]:.1f} +/- {b["sd"]:.1f} K '
|
|
795
|
+
f'(mean and s.d. over {b["n"]} builds)')
|
|
757
796
|
unquotable=[]
|
|
758
797
|
for label,r,(lo,hi) in zip(labels,spread,span):
|
|
759
798
|
if r is None:
|
|
@@ -767,9 +806,9 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
767
806
|
for label,w in zip(labels,whole):
|
|
768
807
|
f=w['fit']
|
|
769
808
|
if f is None:
|
|
770
|
-
logger.info(f'{label} Tg, whole-curve
|
|
809
|
+
logger.info(f'{label} Tg, whole-curve hyperbola (diagnostic, not the reported Tg): did not converge')
|
|
771
810
|
elif f['held_out']:
|
|
772
|
-
logger.info(f'{label} Tg, whole-curve
|
|
811
|
+
logger.info(f'{label} Tg, whole-curve hyperbola (diagnostic, not the reported Tg): none ({f["reason"]})')
|
|
773
812
|
else:
|
|
774
813
|
if w['Tg_boot_sd'] is not None:
|
|
775
814
|
err=(f'+/- {w["Tg_boot_sd"]:.0f} K (uncertainty of the mean, bootstrap over '
|
|
@@ -781,9 +820,30 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
781
820
|
err=f'+/- {f["Tg_synth_sd"]:.0f} K within this build'
|
|
782
821
|
else:
|
|
783
822
|
err='no error bar'
|
|
784
|
-
logger.info(f'{label} Tg, whole-curve
|
|
823
|
+
logger.info(f'{label} Tg, whole-curve hyperbola (diagnostic, not the reported Tg): {f["Tg"]:.1f} K {err}; tangents at the '
|
|
785
824
|
f'ladder ends cross at {f["Tg_tangents"]:.1f} K'
|
|
786
825
|
+ ('; a sharp break' if f['sharp'] else ''))
|
|
826
|
+
bar=w['Tg_boot_sd'] if w['Tg_boot_sd'] is not None else f.get('Tg_synth_sd')
|
|
827
|
+
# a move smaller than one rung is below what the ladder resolves, whatever the
|
|
828
|
+
# error bar says; a noise-free ladder has an error bar of zero
|
|
829
|
+
bar=max(bar or 0.0,w['rung'])
|
|
830
|
+
drift=w.get('ceiling_drift') or []
|
|
831
|
+
if drift:
|
|
832
|
+
logger.info(f'{label} Tg, whole-curve hyperbola with the top of the ladder cut away: '
|
|
833
|
+
+ '; '.join(f'{d["ceiling"]:.0f} K top: '
|
|
834
|
+
+ (f'{d["Tg"]:.1f} K ({d["Tg"]-f["Tg"]:+.1f})'
|
|
835
|
+
if d['Tg'] is not None else f'none ({d["reason"]})')
|
|
836
|
+
for d in drift))
|
|
837
|
+
first_cut=drift[0]
|
|
838
|
+
if first_cut['Tg'] is None:
|
|
839
|
+
logger.warning(f'the {label} whole-curve hyperbola Tg is lost when the top {first_cut["cut"]:.0f} K of '
|
|
840
|
+
f'the ladder is removed: the ladder only just reaches past this '
|
|
841
|
+
f'transition, so raise its top')
|
|
842
|
+
elif abs(first_cut['Tg']-f['Tg'])>bar:
|
|
843
|
+
logger.warning(f'the {label} whole-curve hyperbola Tg moves {first_cut["Tg"]-f["Tg"]:+.1f} K when the '
|
|
844
|
+
f'top {first_cut["cut"]:.0f} K of the ladder is removed, more than '
|
|
845
|
+
f'{bar:.1f} K, the larger of its error bar and one rung: the ladder is not tall enough for '
|
|
846
|
+
f'this Tg to have settled, so raise its top')
|
|
787
847
|
first={}
|
|
788
848
|
for i,label in enumerate(labels):
|
|
789
849
|
first.setdefault(label,i)
|
|
@@ -793,7 +853,27 @@ def do_tg_plots(phases,projdirs,outfile='tg.png',save_data='data.csv',n_points=[
|
|
|
793
853
|
logger.warning(f'heating and cooling Tg differ by {abs(hTg-cTg):.0f} K; more than rate '
|
|
794
854
|
f'hysteresis explains, so treat at least one as a failed fit')
|
|
795
855
|
return {'heating':hTg,'cooling':cTg,'directions':labels,'window_range':spread,
|
|
796
|
-
'unquotable':unquotable,'whole_curve':whole}
|
|
856
|
+
'unquotable':unquotable,'per_build':per_build,'whole_curve':whole}
|
|
857
|
+
|
|
858
|
+
def _crossing_per_build(curves,n_points):
|
|
859
|
+
"""Two-line crossing Tg of each build's own curve: dict with 'Tgs', 'mean', 'sd', 'n'.
|
|
860
|
+
|
|
861
|
+
'sd' is None with fewer than two builds. A build whose curve is too short for the
|
|
862
|
+
fit windows is left out.
|
|
863
|
+
"""
|
|
864
|
+
tgs=[]
|
|
865
|
+
for T,y in curves:
|
|
866
|
+
o=np.argsort(T)
|
|
867
|
+
T,y=np.asarray(T)[o],np.asarray(y)[o]
|
|
868
|
+
if len(T)<n_points[0]+n_points[1]:
|
|
869
|
+
continue
|
|
870
|
+
try:
|
|
871
|
+
tgs.append(float(compute_tg(T,y,n_points=n_points)[0]))
|
|
872
|
+
except (RuntimeError,ValueError,TypeError):
|
|
873
|
+
continue
|
|
874
|
+
n=len(tgs)
|
|
875
|
+
return {'Tgs':tgs,'n':n,'mean':float(np.mean(tgs)) if n else None,
|
|
876
|
+
'sd':float(np.std(tgs,ddof=1)) if n>1 else None}
|
|
797
877
|
|
|
798
878
|
def do_E_plots(phases,projdirs,outfile='e.png',save_data='E.csv',fit_strain=None):
|
|
799
879
|
"""Fits Young's modulus to the deform stages and plots the mean stress-strain curve.
|
|
@@ -820,6 +900,7 @@ def do_E_plots(phases,projdirs,outfile='e.png',save_data='E.csv',fit_strain=None
|
|
|
820
900
|
fit_strain=list(sorted(windows)[0])
|
|
821
901
|
lo,hi=fit_strain
|
|
822
902
|
curves=[]
|
|
903
|
+
missing=[]
|
|
823
904
|
for p in phases:
|
|
824
905
|
params={**PostSimDeform.default_params,**p['deform']}
|
|
825
906
|
dir=params['direction']
|
|
@@ -832,12 +913,25 @@ def do_E_plots(phases,projdirs,outfile='e.png',save_data='E.csv',fit_strain=None
|
|
|
832
913
|
if not found and os.path.isdir(os.path.join(d,params['subdir'])):
|
|
833
914
|
# a run from before replicas existed, or one with replicas: 1
|
|
834
915
|
found=[params['subdir']]
|
|
916
|
+
elif not found:
|
|
917
|
+
missing.append(f'{d}/{params["subdir"]}')
|
|
918
|
+
continue
|
|
835
919
|
elif len(found)<len(subs):
|
|
836
920
|
logger.warning(f'{d}: found {len(found)} of {len(subs)} replica directories for '
|
|
837
921
|
f'{params["subdir"]}; fitting those')
|
|
838
922
|
for sub in found:
|
|
839
923
|
df=pd.read_csv(os.path.join(d,sub,f'deform-{dir}.csv'),index_col=None,header=0)
|
|
840
924
|
curves.append((os.path.join(d,sub),pd.DataFrame({'strain':df[strain_name],'stress':(df[stress_name]*MPa_per_bar)})))
|
|
925
|
+
if not curves:
|
|
926
|
+
# no deform stage has run in any project; a ladder-only project is a normal
|
|
927
|
+
# state, and the Tg output already written must not be undone by an error
|
|
928
|
+
# here (htpolynet-sweep, 2026-11-19: min() of an empty list, after the ladder
|
|
929
|
+
# CSVs were written, made plots post exit nonzero)
|
|
930
|
+
logger.warning(f'no deform stage has run ({", ".join(missing)} not found); '
|
|
931
|
+
f'skipping Young\'s modulus')
|
|
932
|
+
return None
|
|
933
|
+
if missing:
|
|
934
|
+
logger.warning(f'deform stages not found, left out of E: {", ".join(missing)}')
|
|
841
935
|
reached=min(c['strain'].max() for _,c in curves)
|
|
842
936
|
if reached<hi:
|
|
843
937
|
logger.warning(f'the shortest pull reaches strain {reached:.4f}, short of the fit window\'s '
|
|
@@ -905,6 +999,14 @@ def post_plots(args):
|
|
|
905
999
|
mdf=[]
|
|
906
1000
|
for p in args.proj:
|
|
907
1001
|
if 'anneal' in phasenames and 'equilibrate' in phasenames:
|
|
1002
|
+
need=[os.path.join(p,'postsim',s,f'{s}.csv') for s in ('anneal','equilibrate')]
|
|
1003
|
+
absent=[f for f in need if not os.path.exists(f)]
|
|
1004
|
+
if absent:
|
|
1005
|
+
# a stage that has not run is reported, not fatal: it used to raise
|
|
1006
|
+
# here, before the ladders and pulls that had run were analyzed
|
|
1007
|
+
logger.warning(f'{", ".join(absent)} not found; leaving {p} out of the '
|
|
1008
|
+
f'anneal/equilibrate density')
|
|
1009
|
+
continue
|
|
908
1010
|
mdf.append(postsim_density_evolution(p))
|
|
909
1011
|
if mdf:
|
|
910
1012
|
multi_trace(mdf,xnames=['time(ps)']*len(mdf),ynames=['Density']*len(mdf),labels=args.proj,ylabel='Density [kg/m$^3$]',outfile='anneal-equil-density.png')
|
htpolynet/analysis/utils.py
CHANGED
|
@@ -616,6 +616,36 @@ def pooled_tg(curves,n_boot=500,seed=0):
|
|
|
616
616
|
'Tg_boot_sd':sd,'per_build':per,'n_builds':len(curves),'n_kept':len(kept),
|
|
617
617
|
'per_build_sd':float(np.std(kept,ddof=1)) if len(kept)>1 else None}
|
|
618
618
|
|
|
619
|
+
def ceiling_drift(curves,cuts=(50.0,100.0)):
|
|
620
|
+
"""Pooled Tg refitted with the top of the ladder cut away.
|
|
621
|
+
|
|
622
|
+
Passing every check in :func:`fit_tg_hyperbola` says a Tg is not obviously broken,
|
|
623
|
+
not that the ladder was tall enough for it to have settled. Example 1's heating
|
|
624
|
+
Tg moved from 436.4 K on an 800 K ladder to 443.0 K at 700 K and 450.8 K at 650 K,
|
|
625
|
+
kept by every check at each (htpolynet-sweep, plan C, 2026-10-25). How far Tg moves
|
|
626
|
+
as the top comes off is the part of its uncertainty the bootstrap cannot see.
|
|
627
|
+
|
|
628
|
+
Args:
|
|
629
|
+
curves (list): one (T, v) pair of arrays per build
|
|
630
|
+
cuts (tuple): how many K to remove from the top of the ladder, one refit each
|
|
631
|
+
|
|
632
|
+
Returns:
|
|
633
|
+
list: one dict per cut, with cut, ceiling, Tg (None when the refit is held out)
|
|
634
|
+
and reason
|
|
635
|
+
"""
|
|
636
|
+
top=min(float(np.max(t)) for t,_ in curves)
|
|
637
|
+
out=[]
|
|
638
|
+
for cut in cuts:
|
|
639
|
+
ceiling=top-cut
|
|
640
|
+
trimmed=[(np.asarray(t)[np.asarray(t)<=ceiling],np.asarray(y)[np.asarray(t)<=ceiling])
|
|
641
|
+
for t,y in curves]
|
|
642
|
+
r=pooled_tg(trimmed,n_boot=0)
|
|
643
|
+
f=r['fit']
|
|
644
|
+
out.append({'cut':cut,'ceiling':ceiling,'Tg':r['Tg'],
|
|
645
|
+
'reason':None if r['Tg'] is not None
|
|
646
|
+
else (f['reason'] if f is not None else 'did not converge')})
|
|
647
|
+
return out
|
|
648
|
+
|
|
619
649
|
def compute_G(shear_strain,shear_stress,fit_domain=[10,100],fit_strain=None):
|
|
620
650
|
"""Computes the shear modulus by a linear fit to the elastic regime of a simple shear.
|
|
621
651
|
|
htpolynet/core/configuration.py
CHANGED
|
@@ -123,7 +123,12 @@ class Configuration:
|
|
|
123
123
|
self.title = self.basedict.get('Title', 'No title provided')
|
|
124
124
|
self.ncpu = self.basedict.get('ncpu', os.cpu_count())
|
|
125
125
|
self.constituents = self.basedict.get('constituents', {})
|
|
126
|
-
self.reaction_specs = self.basedict.get('reactions', [])
|
|
126
|
+
self.reaction_specs = list(self.basedict.get('reactions', []) or [])
|
|
127
|
+
if any(isinstance(v, dict) and v.get('activate') for v in self.constituents.values()):
|
|
128
|
+
# a constituent given in its real form gets the cap reactions that undo its
|
|
129
|
+
# activation written for it; see external.smiles_input.activate_smiles
|
|
130
|
+
from ..external.smiles_input import activation_cap_reactions
|
|
131
|
+
self.reaction_specs += activation_cap_reactions(self.constituents, self.reaction_specs)
|
|
127
132
|
self.gromacs = self.basedict.get('gromacs', {})
|
|
128
133
|
self.densification = self.basedict.get('densification', {})
|
|
129
134
|
self.precure = self.basedict.get('precure', {})
|
htpolynet/core/molecule.py
CHANGED
|
@@ -547,7 +547,14 @@ class Molecule:
|
|
|
547
547
|
else:
|
|
548
548
|
if self.name != self.parentname:
|
|
549
549
|
logger.info(f'Built {self.name} using topology of {self.parentname}; copying {self.parentname}.top to {self.name}.top')
|
|
550
|
-
|
|
550
|
+
# Read back the mol2 this molecule just wrote, for its bond table only
|
|
551
|
+
# (coordinates stay from the gro). Without it the molecule has no
|
|
552
|
+
# mol2_bonds, and a later template that merges it in -- GMAS-4..15 merge
|
|
553
|
+
# GM1S-k -- kept only its other reactant's bonds: 24 of 78 in example 2
|
|
554
|
+
# (htpolynet-sweep, 2026-11-24). Reading it also runs the bond check now.
|
|
555
|
+
own_mol2 = f'{self.name}.mol2' if os.path.exists(f'{self.name}.mol2') else ''
|
|
556
|
+
self.load_top_gro(f'{self.parentname}.top', f'{self.name}.gro', tpxfilename=f'{self.parentname}.tpx',
|
|
557
|
+
mol2filename=own_mol2, wrap_coords=False)
|
|
551
558
|
shutil.copy(f'{self.parentname}.top', f'{self.name}.top')
|
|
552
559
|
shutil.copy(f'{self.parentname}.grx', f'{self.name}.grx')
|
|
553
560
|
shutil.copy(f'{self.parentname}.tpx', f'{self.name}.tpx')
|
htpolynet/core/topology.py
CHANGED
|
@@ -358,16 +358,23 @@ class Topology:
|
|
|
358
358
|
bmi = grobonds.set_index(['ai', 'aj']).index
|
|
359
359
|
mol2bonds = self.D['mol2_bonds'].sort_values(by=['ai', 'aj'])
|
|
360
360
|
mbmi = mol2bonds.set_index(['ai', 'aj']).index
|
|
361
|
-
|
|
362
|
-
#
|
|
361
|
+
# zip() used to stop at the shorter list, so a mol2 missing only bonds that
|
|
362
|
+
# sort last compared equal and passed (htpolynet-sweep, 2026-11-24)
|
|
363
|
+
canon = lambda idx: {(min(int(a), int(b)), max(int(a), int(b))) for a, b in idx}
|
|
364
|
+
gset, mset = canon(bmi), canon(mbmi)
|
|
365
|
+
check = len(bmi) == len(mbmi) and gset == mset
|
|
363
366
|
if not check:
|
|
364
|
-
logger.error(f'Gromacs/Mol2 bond inconsistency detected'
|
|
367
|
+
logger.error(f'Gromacs/Mol2 bond inconsistency detected: the topology has {len(bmi)} bonds and '
|
|
368
|
+
f'the mol2 {len(mbmi)}; {len(gset - mset)} topology bonds are missing from the mol2 '
|
|
369
|
+
f'and {len(mset - gset)} mol2 bonds are not in the topology')
|
|
365
370
|
logger.debug(f'GROMACS:')
|
|
366
371
|
logger.debug(grobonds[['ai','aj']].head().to_string())
|
|
367
372
|
logger.debug(f'MOL2:')
|
|
368
373
|
logger.debug(mol2bonds[['ai','aj']].head().to_string())
|
|
369
374
|
for x, y in zip(bmi, mbmi):
|
|
370
375
|
logger.debug(f'{x} {y} {x == y}')
|
|
376
|
+
return check
|
|
377
|
+
return None
|
|
371
378
|
|
|
372
379
|
def shiftatomsidx(self, idxshift, directive, rows=[], idxlabels=[]):
|
|
373
380
|
"""Shifts all atom indexes in a topology directive dataframe.
|
|
@@ -1175,9 +1182,36 @@ class Topology:
|
|
|
1175
1182
|
for t in L:
|
|
1176
1183
|
self._myconcat(other, directive=t, drop_duplicates=True)
|
|
1177
1184
|
|
|
1185
|
+
def _fill_missing_mol2_bonds(self, other):
|
|
1186
|
+
"""Before a merge, gives a mol2 bond table to whichever side has bonds but none.
|
|
1187
|
+
|
|
1188
|
+
``_myconcat`` skips a directive the incoming side lacks, so merging a molecule
|
|
1189
|
+
with no mol2 table into one that has one kept only the first's bonds: example 2's
|
|
1190
|
+
GMAS-4..15 templates were written with 24 of their 78 bonds (htpolynet-sweep,
|
|
1191
|
+
2026-11-24). The reverse case adopted the incoming table without shifting its
|
|
1192
|
+
atom indices. The missing table is built from the GROMACS bonds, as single bonds
|
|
1193
|
+
since a topology carries no bond orders, and the gap is logged. Nothing happens
|
|
1194
|
+
when neither side has a table, or when a side has no bonds at all (an empty
|
|
1195
|
+
Topology about to receive its first molecule).
|
|
1196
|
+
"""
|
|
1197
|
+
def has_bonds(T):
|
|
1198
|
+
return 'bonds' in T.D and not T.D['bonds'].empty
|
|
1199
|
+
sides = [(self, 'the molecule being built'), (other, 'the molecule merged into it')]
|
|
1200
|
+
if not any('mol2_bonds' in T.D for T, _ in sides):
|
|
1201
|
+
return
|
|
1202
|
+
for T, label in sides:
|
|
1203
|
+
if 'mol2_bonds' not in T.D and has_bonds(T):
|
|
1204
|
+
b = T.D['bonds'][['ai', 'aj']].reset_index(drop=True)
|
|
1205
|
+
T.D['mol2_bonds'] = pd.DataFrame({'bondIdx': range(1, len(b) + 1), 'ai': b['ai'].astype(int),
|
|
1206
|
+
'aj': b['aj'].astype(int), 'order': '1'})
|
|
1207
|
+
logger.warning(f'{label} has no mol2 bond table; using its {len(b)} topology bonds, '
|
|
1208
|
+
f'as single bonds, so the merged table is complete')
|
|
1209
|
+
|
|
1178
1210
|
def merge_ex(self, other):
|
|
1179
1211
|
logger.debug(f' extensive merging...')
|
|
1180
1212
|
''' merge EXTENSIVE quantities '''
|
|
1213
|
+
# before any concat: _myconcat shifts the incoming side's indices in place
|
|
1214
|
+
self._fill_missing_mol2_bonds(other)
|
|
1181
1215
|
idxshift = 0 if 'atoms' not in self.D else len(self.D['atoms'])
|
|
1182
1216
|
rdxshift = 0 if 'atoms' not in self.D else self.D['atoms'].iloc[-1]['resnr']
|
|
1183
1217
|
if 'atoms' in other.D:
|
htpolynet/cure/curecontroller.py
CHANGED
|
@@ -296,6 +296,7 @@ class CureController:
|
|
|
296
296
|
'desired_conversion': 0.5,
|
|
297
297
|
'min_allowable_bondcycle_length':-1, # not set
|
|
298
298
|
'min_bonds_per_iteration': 10, # grow radius until >= this many bonds (or max radius)
|
|
299
|
+
'min_bond_fraction_per_iteration': 0.0, # ...or this fraction of 100% conversion, if larger
|
|
299
300
|
'completion_bias': False, # rank bond candidates by B-side completion before distance
|
|
300
301
|
'ncpu' : os.cpu_count()
|
|
301
302
|
},
|
|
@@ -356,6 +357,21 @@ class CureController:
|
|
|
356
357
|
if (d['nstages']>0 or d['increment']>0.0) and d['limit']>0.0:
|
|
357
358
|
self.dragging_enabled=True
|
|
358
359
|
|
|
360
|
+
def bond_floor(self,bond_target,bond_limit):
|
|
361
|
+
"""How many bonds an iteration should find before it stops widening the radius.
|
|
362
|
+
|
|
363
|
+
The larger of ``min_bonds_per_iteration`` and ``min_bond_fraction_per_iteration``
|
|
364
|
+
of the bonds at 100% conversion. A count alone does not scale with the box: a
|
|
365
|
+
larger box finds more candidates at the same concentration and may never widen.
|
|
366
|
+
The fraction defaults to 0, which leaves the count in charge, as before. The floor
|
|
367
|
+
is clamped against the bonds still needed (``bond_target``) and the most the
|
|
368
|
+
iteration will accept (``bond_limit``), and is never below 1.
|
|
369
|
+
"""
|
|
370
|
+
d=self.dicts['controls']
|
|
371
|
+
base=max(int(d.get('min_bonds_per_iteration',1)),
|
|
372
|
+
int(np.floor(float(d.get('min_bond_fraction_per_iteration',0.0))*self.state.max_nxlinkbonds+1.e-9)))
|
|
373
|
+
return max(1,min(base,bond_target,bond_limit))
|
|
374
|
+
|
|
359
375
|
def setup(self,max_nxlinkbonds=0,desired_nxlinkbonds=0,max_search_radius=0.0):
|
|
360
376
|
"""Sets up this CureController object.
|
|
361
377
|
|
|
@@ -497,7 +513,7 @@ class CureController:
|
|
|
497
513
|
# possible) and bond_limit (don't demand more than we'd accept).
|
|
498
514
|
# If we hit max radius with fewer than this many but at least one,
|
|
499
515
|
# we still proceed -- the post-loop branch handles that.
|
|
500
|
-
min_floor=
|
|
516
|
+
min_floor=self.bond_floor(bond_target,bond_limit)
|
|
501
517
|
logger.debug(f'Iteration will grow radius until >= {min_floor} bonds (or max radius)')
|
|
502
518
|
nbdf=pd.DataFrame()
|
|
503
519
|
nbonds=0
|
htpolynet/cure/ringcontroller.py
CHANGED
|
@@ -111,6 +111,7 @@ class RingController:
|
|
|
111
111
|
'desired_conversion': 0.95,
|
|
112
112
|
'max_rings_per_iteration': 0,
|
|
113
113
|
'min_rings_per_iteration': 4,
|
|
114
|
+
'min_ring_fraction_per_iteration': 0.0167,
|
|
114
115
|
'reject_threaded_rings': True,
|
|
115
116
|
'prefilter_threaded_candidates': False,
|
|
116
117
|
'reject_new_threading': True,
|
|
@@ -186,12 +187,23 @@ class RingController:
|
|
|
186
187
|
150 bisphenol A dicyanates, that is conversion 0.40 in eight iterations rather
|
|
187
188
|
than the 0.60 asked for.
|
|
188
189
|
|
|
190
|
+
The floor is the larger of ``min_rings_per_iteration`` and
|
|
191
|
+
``min_ring_fraction_per_iteration`` of the rings the whole system could form. A
|
|
192
|
+
count alone does not scale with the box: at a given concentration of unreacted
|
|
193
|
+
groups a box 8 times larger finds 8 times the candidates, never drops below a floor
|
|
194
|
+
of 4, never widens, and so never reaches the macrocycles a cyanate ester needs
|
|
195
|
+
beyond 75 % conversion. Example 6 at 2880 monomers stalled at 0.75 that way
|
|
196
|
+
(htpolynet-sweep, 2026-11-09). The default fraction, 0.0167, gives 4 at the 360
|
|
197
|
+
monomers the floor of 4 was set on, and 32 at 2880.
|
|
198
|
+
|
|
189
199
|
The floor is clamped against the rings still needed to reach the target, so the
|
|
190
200
|
last iteration does not widen in search of rings it would decline to form.
|
|
191
201
|
"""
|
|
192
202
|
remaining = self.dicts['desired_conversion'] * self.state.total_groups - self.state.groups_consumed
|
|
193
203
|
needed = max(1, int(np.ceil(remaining / 3.0)))
|
|
194
|
-
|
|
204
|
+
scaled = int(np.floor(float(self.dicts.get('min_ring_fraction_per_iteration', 0.0))
|
|
205
|
+
* self.state.total_groups / 3.0 + 1.e-9))
|
|
206
|
+
floor = min(max(int(self.dicts['min_rings_per_iteration']), scaled), needed)
|
|
195
207
|
if self.dicts['max_rings_per_iteration']:
|
|
196
208
|
floor = min(floor, int(self.dicts['max_rings_per_iteration']))
|
|
197
209
|
return max(1, floor)
|