o
    ߥi	                     @   s   d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZ ddlmZ dd	lmZ d
gZe
jejejdG dd
 d
eZdd ZdS )    N)Any)Models)
TorchModel)MODELS)	ModelFileTasks   )model_config)	AlphaFoldUnifoldForProteinStructrue)module_namec                       sL   e Zd Zedd Z fddZdd Zdd Zed	d
 Z	dd Z
  ZS )r   c                 C   s   | j ddd dS )z+Add model-specific arguments to the parser.z--model-namezchoose the model config)helpN)add_argument)parser r   [/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/science/unifold/model.pyadd_args   s   
z#UnifoldForProteinStructrue.add_argsc           	         s   t    t }g }|D ]}|d|  |d|  |||  q||}t| || _t	| jj
dd}t|| _|| _tj|d tj}t|d d }dd | D }| j| d S )	Nz--T)train	model_diremaparamsc                 S   s*   i | ]\}}d  |d dd |qS ).r   N)joinsplit).0kvr   r   r   
<dictcomp>5   s    z7UnifoldForProteinStructrue.__init__.<locals>.<dictcomp>)super__init__argparseArgumentParserr   append
parse_argsbase_architectureargsr	   
model_namer
   modelconfigospathr   r   TORCH_MODEL_BIN_FILEtorchloaditemsload_state_dict)	selfkwargsr   
parse_commkeyr%   r(   
param_path
state_dict	__class__r   r   r      s0   


z#UnifoldForProteinStructrue.__init__c                 C      | j  | _ | S N)r'   halfr0   r   r   r   r:   ;      zUnifoldForProteinStructrue.halfc                 C   r8   r9   )r'   bfloat16r;   r   r   r   r=   ?   r<   z#UnifoldForProteinStructrue.bfloat16c                 C   s   | |S )zBuild a new model instance.r   )clsr%   taskr   r   r   build_modelC   s   z&UnifoldForProteinStructrue.build_modelc                 K   s   | j |}|| jjfS r9   )r'   forwardr(   loss)r0   batchr1   outputsr   r   r   rA   H   s   z"UnifoldForProteinStructrue.forward)__name__
__module____qualname__staticmethodr   r   r:   r=   classmethodr@   rA   __classcell__r   r   r6   r   r      s    

c                 C   s   t | dd| _d S )Nr&   model_2)getattrr&   )r%   r   r   r   r$   M   s   r$   )r    r)   typingr   r,   modelscope.metainfor   modelscope.modelsr   modelscope.models.builderr   modelscope.utils.constantr   r   r(   r	   modules.alphafoldr
   __all__register_moduleprotein_structureunifoldr   r$   r   r   r   r   <module>   s   8