Team Ai
Modelpublic

OneScience-Group/DiffDock

sourceHugging Facemitupdated 2mo agoView on Hugging Face
0likes53downloads
score_wrapper.cpython-310.pyc49 linesDownload Raw Back to __pycache__
1o

2�aOj4�@s�ddlmZddlmZddlmZddlZddlZddlm	Z	ddl3mZmZ
ddlmZdd	lmZdd4lmZddlmZdZd
d�Zdd�Zdd�Zddd�Zddd�Z			ddd�Z					ddd�ZdS) �)�	Namespace)�partial)�PathN)�DataParallel)�get_timestep_embedding�5t_to_sigma)�ExponentialMovingAverage�)�AAModel)�CGModel)�6AAOldModel)�moad_esm_embeddings_path�pdbbind_esm_embeddings_path� pdbsidechain_esm_embeddings_path�esm_embeddings_path�esm_embeddings_modelcCsZt|�}|d}|jddd��}t�|�pi}Wd�n1s!wYtdi|��S)Nzmodel_parameters.yml�rzutf-8)�encoding�)r�open�yamlZ	full_loadr)�	model_dirZconfig_pathZhandleZconfigrr�+modelscope/diffdock/models/score_wrapper.py�load_model_argss�rcst�fdd�tD��S)Nc3s �|]}t�|d�duVqdS�N)�getattr)�.0�key��7model_argsrr�	<genexpr>#s�z+model_uses_lm_embeddings.<locals>.<genexpr>)�any�_LM_EMBEDDING_KEYSrrrr�model_uses_lm_embeddings"sr#cCs(z||vWStyt||�YSwr)�	TypeError�hasattr)�args�namerrr�_has_arg&s89�r(cCs.t|t�r|�||�St||�rt||�S|Sr)�10isinstance�dict�getr(r)r&r'�defaultrrr�_get_arg-s11121314r-Fc
Cs|tt|dd�|jt|dd�d�}t|dd�}|r|std��d}t|d	�dus<t|d15�dus<t|d�dus<t|d�dur>d
}t|d�durH|j}|rMt}	n|rRt}	nt}	tdLid|�d|�d|j	�d|�d|j16�d|j�d|j�d|j�dt|dd��d|j
�d|j�d|j�d|j�d|j�d|j�d|j�d|j�d |j�d!t|d!d��d"t|d"d��d#|�d$|�d%t|d%d&��d't|d'd��d(t|d(d��d)t|d)d*��d+tt|d,�t�r�t|j�d*nd*�d-tt|d.�t�r�t|j�d*nd*�d/t|d/d0��d1t|d2d��d3t|d3d��d4t|d4d��d5t|d5d6��d7t|d8d��d9t|d9d6��d:t|d:d;��d<t|d<d��d=t|d=d��d>t|d?d&�d&k�d@t|dA��rR|jd;k�p\t|dB��o\|jd;k�dCt|dCd���}17|	tu�rtt|dDd�|18dD<n'|	tu�r�dED]	}|19�|d��q{t|d�du�r�dFnd|20d#<t|dGdH�|21dG<|	dLi|22��}|jdIk�r�|�s�t|dJ�dKk�r�t |�}|�!|�|S)MN�embedding_typeZ23sinusoidal�embedding_scalei')r.Z
embedding_dimr/�	all_atomsFz�The old coarse-grained DiffDock model path is not migrated yet. Use old=True only with all_atoms=True, or migrate old_cg_model.py first.r
rrrZprecomputedrr�device�24no_torsion�timestep_emb_func�num_conv_layersZlig_max_radius�scale_by_sigma�sigma_embed_dimZ
norm_by_sigma�ns�nv�distance_embed_dim�cross_distance_embed_dimZ25batch_norm�dropout�use_second_order_repr�cross_max_distance�dynamic_max_crossZsmooth_edgesZ26odd_parity�lm_embedding_type�confidence_modeZconfidence_dropoutgZconfidence_no_batchnormZaffinity_predictionZparallelr	Znum_confidence_outputs�rmsd_classification_cutoff�atom_num_confidence_outputs�atom_rmsd_classification_cutoffZparallel_aggregators�Zfixed_center_convZnot_fixed_center_convZno_aminoacid_identitiesZinclude_miscellaneous_atomsZsh_lmax��differentiate_convolutionsZno_differentiate_convolutions�tp_weights_layers�num_prot_emb_layersr�reduce_pseudoscalars�embed_also_ligand�atom_confidenceZatom_confidence_loss_weight�sidechain_pred�sidechain_loss_weight�backbone_loss_weight�depthwise_convolutionZcrop_beyond)	rBrFrGrHrIrJrKrLrOZesmZuse_old_atom_encoderT�cudaZdatasetZ	torsionalr)"rr-r6�NotImplementedErrorrrr27rr*r2r4Z28max_radiusr5r7r8r9r:Z
no_batch_normr;r<r=r>r)�list�lenrArCr(rMrN�pop�typer�to)
r&r1r�no_parallelr@�oldr3r0r?Zmodel_classZmodel_kwargsr�modelrrr�	get_model5s�2930����������	�31���
�����������������"���%�&�'�(�)�*�+�,�-�.�/�1��4�32633�"34rZcCs(tt|d�}t||||||d�}||fS)N)r&)rrWr@rX)r�t_to_sigma_complrZ)rr1rWr@rXrrYrrr�build_score_model�s�r\Tc
Cs|durt�tj��r
dnd�}t|�}t|||||d�\}}	t|�|}35tj|36t�d�d�}t|t	�rkd|vrkd|vrk|j37|d|d�d|vrjt|d	d�durjt|�
�|jd38�}|j39|d|d�|�|�
��n|j40||d�|�|�}|��|||	fS)NrPZcpu)rr1rWr@rX)Zmap_locationrYZ	optimizer)�strict�ema_weights�ema_rate)Zdecay)r1)�torchr1rPZis_availablerr\r�loadr)r*Zload_state_dictrrZ41parametersr_Zcopy_torV�eval)
rZckptr1rWr@rXr]rrYrZcheckpoint_pathZ42state_dictr^rrr�load_score_model�s.	43��4445rcr)FFF)NTFFT)�argparser�	functoolsrZpathlibrr`rZ torch_geometric.nn.data_parallelrZ)onescience.utils.diffdock.diffusion_utilsrrr[Zonescience.utils.diffdock.utilsrZaa_modelr46Zcg_modelrZold_aa_modelrr"rr#r(r-rZr\rcrrrr�<module>s6	4748u49��